Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / search_engines / search_provider_install_data.h
blob84e34739fea7bd2ff28f3483dfc6240cc57e7dc5
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"
16 #include "chrome/browser/webdata/web_data_service.h"
18 class GURL;
19 class SearchHostToURLsMap;
20 class TemplateURL;
22 namespace content {
23 class NotificationSource;
26 // Provides the search provider install state for the I/O thread. It works by
27 // loading the data on demand (when CallWhenLoaded is called) and then throwing
28 // away the results after the callbacks are done, so the results are always up
29 // to date with what is in the database.
30 class SearchProviderInstallData : public WebDataServiceConsumer,
31 public base::SupportsWeakPtr<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 // |ui_death_notification| and |ui_death_source| identify a notification that
45 // may be observed on the UI thread to know when this class no longer needs to
46 // be kept up to date. (Note that this class may be deleted before or after
47 // that notification occurs. It doesn't matter.)
48 SearchProviderInstallData(Profile* profile,
49 int ui_death_notification,
50 const content::NotificationSource& ui_death_source);
51 virtual ~SearchProviderInstallData();
53 // Use to determine when the search provider information is loaded. The
54 // callback may happen synchronously or asynchronously. There is no need to do
55 // anything special to make it function (as it just relies on the normal I/O
56 // thread message loop).
57 void CallWhenLoaded(const base::Closure& closure);
59 // Returns the search provider install state for the given origin.
60 // This should only be called while a task is called back from CallWhenLoaded.
61 State GetInstallState(const GURL& requested_origin);
63 // Called when the google base url has changed.
64 void OnGoogleURLChange(const std::string& google_base_url);
66 private:
67 // WebDataServiceConsumer
68 // Notification that the keywords have been loaded.
69 // This is invoked from WebDataService, and should not be directly
70 // invoked.
71 virtual void OnWebDataServiceRequestDone(
72 WebDataService::Handle h,
73 const WDTypedResult* result) OVERRIDE;
75 // Stores information about the default search provider.
76 void SetDefault(const TemplateURL* template_url);
78 // Sets up the loaded state and then lets clients know that the search
79 // provider install state has been loaded.
80 void OnLoadFailed();
82 // Does notifications to let clients know that the search provider
83 // install state has been loaded.
84 void NotifyLoaded();
86 // The list of closures to call after the load has finished.
87 std::vector<base::Closure> closure_queue_;
89 // Service used to store entries.
90 scoped_refptr<WebDataService> web_service_;
92 // If non-zero, we're waiting on a load.
93 WebDataService::Handle load_handle_;
95 // Holds results of a load that was done using this class.
96 scoped_ptr<SearchHostToURLsMap> provider_map_;
98 // The list of template urls that are owned by the class.
99 ScopedVector<TemplateURL> template_urls_;
101 // The security origin for the default search provider.
102 std::string default_search_origin_;
104 // The google base url.
105 std::string google_base_url_;
107 DISALLOW_COPY_AND_ASSIGN(SearchProviderInstallData);
110 #endif // CHROME_BROWSER_SEARCH_ENGINES_SEARCH_PROVIDER_INSTALL_DATA_H_