Roll src/third_party/WebKit f298044:aa8346d (svn 202628:202629)
[chromium-blink-merge.git] / chrome / browser / search_engines / search_provider_install_data.h
blob512da28a271210e8857ca40ec74242351453724b
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_SEARCH_ENGINES_SEARCH_PROVIDER_INSTALL_DATA_H_
6 #define CHROME_BROWSER_SEARCH_ENGINES_SEARCH_PROVIDER_INSTALL_DATA_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/scoped_vector.h"
15 #include "base/memory/weak_ptr.h"
17 class GURL;
18 class GoogleURLTracker;
19 class SearchHostToURLsMap;
20 class TemplateURL;
21 class TemplateURLService;
23 namespace content {
24 class RenderProcessHost;
27 // Provides the search provider install state for the I/O thread. It works by
28 // loading the data on demand (when CallWhenLoaded is called) and then throwing
29 // away the results after the callbacks are done, so the results are always up
30 // to date with what is in the database.
31 class SearchProviderInstallData {
32 public:
33 enum State {
34 // The search provider is not installed.
35 NOT_INSTALLED = 0,
37 // The search provider is in the user's set but is not
38 INSTALLED_BUT_NOT_DEFAULT = 1,
40 // The search provider is set as the user's default.
41 INSTALLED_AS_DEFAULT = 2
44 // |host| is a RenderProcessHost that is observed, and whose destruction is a
45 // signal to this class that it no longer needs to be kept up to date. (Note
46 // that this class may be deleted before or after that death occurs. It
47 // doesn't matter.)
48 SearchProviderInstallData(TemplateURLService* template_url_service,
49 const std::string& google_base_url,
50 GoogleURLTracker* google_url_tracker,
51 content::RenderProcessHost* host);
52 virtual ~SearchProviderInstallData();
54 // Use to determine when the search provider information is loaded. The
55 // callback may happen synchronously or asynchronously. There is no need to do
56 // anything special to make it function (as it just relies on the normal I/O
57 // thread message loop).
58 void CallWhenLoaded(const base::Closure& closure);
60 // Returns the search provider install state for the given origin.
61 // This should only be called while a task is called back from CallWhenLoaded.
62 State GetInstallState(const GURL& requested_origin);
64 // Called when the google base url has changed.
65 void OnGoogleURLChange(const std::string& google_base_url);
67 private:
68 // Receives a copy of the TemplateURLService's keywords on the IO thread.
69 void OnTemplateURLsLoaded(ScopedVector<TemplateURL> template_urls,
70 TemplateURL* default_provider);
72 // Stores information about the default search provider.
73 void SetDefault(const TemplateURL* template_url);
75 // Sets up the loaded state and then lets clients know that the search
76 // provider install state has been loaded.
77 void OnLoadFailed();
79 // Does notifications to let clients know that the search provider
80 // install state has been loaded.
81 void NotifyLoaded();
83 // The original data source. Only accessed on the UI thread.
84 TemplateURLService* template_url_service_;
86 // The list of closures to call after the load has finished. If empty, there
87 // is no pending load.
88 std::vector<base::Closure> closure_queue_;
90 // Holds results of a load that was done using this class.
91 scoped_ptr<SearchHostToURLsMap> provider_map_;
93 // The list of template urls that are owned by the class.
94 ScopedVector<TemplateURL> template_urls_;
96 // The security origin for the default search provider.
97 std::string default_search_origin_;
99 // The google base url.
100 std::string google_base_url_;
102 base::WeakPtrFactory<SearchProviderInstallData> weak_factory_;
104 DISALLOW_COPY_AND_ASSIGN(SearchProviderInstallData);
107 #endif // CHROME_BROWSER_SEARCH_ENGINES_SEARCH_PROVIDER_INSTALL_DATA_H_