<html>
    <head>
      <base href="https://bugs.webkit.org/" />
    </head>
    <body>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - We should be able to clear search field recent searches based on time given"
   href="https://bugs.webkit.org/show_bug.cgi?id=150019#c3">Comment # 3</a>
              on <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - We should be able to clear search field recent searches based on time given"
   href="https://bugs.webkit.org/show_bug.cgi?id=150019">bug 150019</a>
              from <span class="vcard"><a class="email" href="mailto:zacharyli323&#64;gmail.com" title="Zach Li &lt;zacharyli323&#64;gmail.com&gt;"> <span class="fn">Zach Li</span></a>
</span></b>
        <pre>(In reply to <a href="show_bug.cgi?id=150019#c2">comment #2</a>)
<span class="quote">&gt; Comment on <span class=""><a href="attachment.cgi?id=262876&amp;action=diff" name="attach_262876" title="Patch">attachment 262876</a> <a href="attachment.cgi?id=262876&amp;action=edit" title="Patch">[details]</a></span>
&gt; Patch
&gt; 
&gt; View in context:
&gt; <a href="https://bugs.webkit.org/attachment.cgi?id=262876&amp;action=review">https://bugs.webkit.org/attachment.cgi?id=262876&amp;action=review</a>
&gt; 
&gt; &gt; Source/WebCore/platform/cocoa/SearchPopupMenuCocoa.h:35
&gt; &gt; +WEBCORE_EXPORT void removeSearchFieldRecentSearchesModifiedSince(std::chrono::system_clock::time_point modifiedSince);
&gt; 
&gt; This can probably just be a static function in SearchPopupMenu, and then it
&gt; can have a shorter name.</span >

SearchPopupMenu is only a header file. And this function will only work on cocoa platform and I want to be consistent with the functions I already declared which are saveRecentSearches and loadRecentSearches.

<span class="quote">&gt; 
&gt; &gt; Source/WebCore/platform/cocoa/SearchPopupMenuCocoa.mm:148
&gt; &gt; +        NSMutableDictionary *emptyRecentSearchesDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:[NSMutableDictionary dictionary], itemsKey, nil];
&gt; &gt; +        [emptyRecentSearchesDictionary writeToFile:searchFieldRecentSearchesPlistPath() atomically:NO];
&gt; 
&gt; Can we just delete this file instead of writing an empty file? Does the
&gt; presence of a file signify something? Does it need to include this key-value
&gt; pair? Why is everything here mutable?</span >

The presence of the file does not signify anything if it is empty. But this is following the behavior in saveRecentSearches that we will overwrite the plist to be an empty file when we detect the plist is corrupted instead of deleting the file.

The key-value pair is there to make saveRecentSearches easier when we construct the plist.

Not sure if it adds any value by making them mutable because the mutability will not be reserved when saving as a plist? But we do expect them to be mutable when reading the plist.

<span class="quote">&gt; 
&gt; &gt; Source/WebCore/platform/cocoa/SearchPopupMenuCocoa.mm:149
&gt; &gt; +    }
&gt; 
&gt; Did you mean to return early after this?</span >

Yup!

<span class="quote">&gt; 
&gt; &gt; Source/WebCore/platform/cocoa/SearchPopupMenuCocoa.mm:153
&gt; &gt; +    if (![[itemsDictionary classForCoder] isSubclassOfClass:[NSMutableDictionary class]])
&gt; 
&gt; What is the significance of checking this way vs. the -isKindOfClass: checks
&gt; below?
&gt; </span >

Remy explained to me that [itemsDictionary isKindOfClass:[NSMutableDictionary class]] can return true even if itemsDictionary is not mutable because of the presence of __NSCFDictionary inside NSMutableDictionary. We have this check in Safari codebase.

<span class="quote">&gt; &gt; Source/WebCore/platform/cocoa/SearchPopupMenuCocoa.mm:158
&gt; &gt; +        if (![key isKindOfClass:[NSString class]])
&gt; 
&gt; I mean this…
&gt; 
&gt; &gt; Source/WebCore/platform/cocoa/SearchPopupMenuCocoa.mm:162
&gt; &gt; +        if (![[nameDictionary classForCoder] isSubclassOfClass:[NSMutableDictionary class]])
&gt; 
&gt; …versus this.
&gt; 
&gt; &gt; Source/WebKit2/Shared/WebsiteData/WebsiteDataTypes.h:48
&gt; &gt; +    WebsiteDataTypeSearchFieldRecentSearches = 1 &lt;&lt; 10,
&gt; &gt;  #if ENABLE(NETSCAPE_PLUGIN_API)
&gt; &gt; -    WebsiteDataTypePlugInData = 1 &lt;&lt; 10,
&gt; &gt; +    WebsiteDataTypePlugInData = 1 &lt;&lt; 11,
&gt; &gt;  #endif
&gt; &gt;  #if ENABLE(MEDIA_STREAM)
&gt; &gt; -    WebsiteDataTypeMediaDeviceIdentifier = 1 &lt;&lt; 11,
&gt; &gt; +    WebsiteDataTypeMediaDeviceIdentifier = 1 &lt;&lt; 12,
&gt; &gt;  #endif
&gt; 
&gt; Why insert this in the middle?</span >

No particular reason. I guess I want to put it before those conditionals.

<span class="quote">&gt; 
&gt; &gt; Source/WebKit2/UIProcess/API/Cocoa/WKWebsiteDataRecordPrivate.h:32
&gt; &gt; +WK_EXTERN NSString * const _WKWebsiteDataTypeSearchFieldRecentSearches WK_AVAILABLE(10_11, 9_0);
&gt; 
&gt; This is not present in 10.11 and 9.0. You should use WK_MAC_TBA and
&gt; WK_IOS_TBA instead.</span >

Will fix.

<span class="quote">&gt; 
&gt; &gt; Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.cpp:40
&gt; &gt; +#if PLATFORM(COCOA)
&gt; &gt; +#include &lt;WebCore/SearchPopupMenuCocoa.h&gt;
&gt; &gt; +#endif
&gt; 
&gt; Conditional imports go in a separate paragraph after the main block of
&gt; imports.</span >

Will fix.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>