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_
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"
18 class GoogleURLTracker
;
19 class SearchHostToURLsMap
;
21 class TemplateURLService
;
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
{
34 // The search provider is not installed.
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
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
);
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.
79 // Does notifications to let clients know that the search provider
80 // install state has been loaded.
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_