OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/webdata/web_data_service.h" | 5 #include "chrome/browser/webdata/web_data_service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
10 #include "chrome/browser/search_engines/template_url.h" | 10 #include "chrome/browser/search_engines/template_url.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 | 36 |
37 WDKeywordsResult::WDKeywordsResult() | 37 WDKeywordsResult::WDKeywordsResult() |
38 : default_search_provider_id(0), | 38 : default_search_provider_id(0), |
39 builtin_keyword_version(0) { | 39 builtin_keyword_version(0) { |
40 } | 40 } |
41 | 41 |
42 WDKeywordsResult::~WDKeywordsResult() {} | 42 WDKeywordsResult::~WDKeywordsResult() {} |
43 | 43 |
44 WebDataService::WebDataService(scoped_refptr<WebDatabaseService> wdbs, | 44 WebDataService::WebDataService(scoped_refptr<WebDatabaseService> wdbs, |
45 const ProfileErrorCallback& callback) | 45 const ProfileErrorCallback& callback) |
46 : WebDataServiceBase(wdbs, callback, | 46 : WebDataServiceBase( |
| 47 wdbs, callback, |
47 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI)) { | 48 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI)) { |
48 } | 49 } |
49 | 50 |
50 ////////////////////////////////////////////////////////////////////////////// | 51 ////////////////////////////////////////////////////////////////////////////// |
51 // | 52 // |
52 // Keywords. | 53 // Keywords. |
53 // | 54 // |
54 ////////////////////////////////////////////////////////////////////////////// | 55 ////////////////////////////////////////////////////////////////////////////// |
55 | 56 |
56 void WebDataService::AddKeyword(const TemplateURLData& data) { | 57 void WebDataService::AddKeyword(const TemplateURLData& data) { |
57 wdbs_->ScheduleDBTask( | 58 wdbs_->ScheduleDBTask( |
58 FROM_HERE, Bind(&WebDataService::AddKeywordImpl, this, data)); | 59 FROM_HERE, Bind(&WebDataService::AddKeywordImpl, this, data)); |
59 } | 60 } |
60 | 61 |
61 void WebDataService::RemoveKeyword(TemplateURLID id) { | 62 void WebDataService::RemoveKeyword(TemplateURLID id) { |
62 wdbs_->ScheduleDBTask( | 63 wdbs_->ScheduleDBTask( |
63 FROM_HERE, Bind(&WebDataService::RemoveKeywordImpl, this, id)); | 64 FROM_HERE, Bind(&WebDataService::RemoveKeywordImpl, this, id)); |
64 } | 65 } |
65 | 66 |
66 void WebDataService::UpdateKeyword(const TemplateURLData& data) { | 67 void WebDataService::UpdateKeyword(const TemplateURLData& data) { |
67 wdbs_->ScheduleDBTask( | 68 wdbs_->ScheduleDBTask( |
68 FROM_HERE, Bind(&WebDataService::UpdateKeywordImpl, this, data)); | 69 FROM_HERE, Bind(&WebDataService::UpdateKeywordImpl, this, data)); |
69 } | 70 } |
70 | 71 |
71 WebDataServiceBase::Handle WebDataService::GetKeywords( | 72 WebDataServiceBase::Handle WebDataService::GetKeywords( |
72 WebDataServiceConsumer* consumer) { | 73 WebDataServiceConsumer* consumer) { |
73 return wdbs_->ScheduleDBTaskWithResult(FROM_HERE, | 74 return wdbs_->ScheduleDBTaskWithResult( |
74 Bind(&WebDataService::GetKeywordsImpl, this), consumer); | 75 FROM_HERE, Bind(&WebDataService::GetKeywordsImpl, this), consumer); |
75 } | 76 } |
76 | 77 |
77 void WebDataService::SetDefaultSearchProvider(const TemplateURL* url) { | 78 void WebDataService::SetDefaultSearchProviderID(TemplateURLID id) { |
78 wdbs_->ScheduleDBTask(FROM_HERE, | 79 wdbs_->ScheduleDBTask( |
79 Bind(&WebDataService::SetDefaultSearchProviderImpl, this, | 80 FROM_HERE, Bind(&WebDataService::SetDefaultSearchProviderImpl, this, id)); |
80 url ? url->id() : 0)); | |
81 } | 81 } |
82 | 82 |
83 void WebDataService::SetBuiltinKeywordVersion(int version) { | 83 void WebDataService::SetBuiltinKeywordVersion(int version) { |
84 wdbs_->ScheduleDBTask(FROM_HERE, | 84 wdbs_->ScheduleDBTask( |
| 85 FROM_HERE, |
85 Bind(&WebDataService::SetBuiltinKeywordVersionImpl, this, version)); | 86 Bind(&WebDataService::SetBuiltinKeywordVersionImpl, this, version)); |
86 } | 87 } |
87 | 88 |
88 ////////////////////////////////////////////////////////////////////////////// | 89 ////////////////////////////////////////////////////////////////////////////// |
89 // | 90 // |
90 // Web Apps | 91 // Web Apps |
91 // | 92 // |
92 ////////////////////////////////////////////////////////////////////////////// | 93 ////////////////////////////////////////////////////////////////////////////// |
93 | 94 |
94 void WebDataService::SetWebAppImage(const GURL& app_url, | 95 void WebDataService::SetWebAppImage(const GURL& app_url, |
(...skipping 16 matching lines...) Expand all Loading... |
111 | 112 |
112 WebDataServiceBase::Handle WebDataService::GetWebAppImages( | 113 WebDataServiceBase::Handle WebDataService::GetWebAppImages( |
113 const GURL& app_url, WebDataServiceConsumer* consumer) { | 114 const GURL& app_url, WebDataServiceConsumer* consumer) { |
114 return wdbs_->ScheduleDBTaskWithResult(FROM_HERE, | 115 return wdbs_->ScheduleDBTaskWithResult(FROM_HERE, |
115 Bind(&WebDataService::GetWebAppImagesImpl, this, app_url), consumer); | 116 Bind(&WebDataService::GetWebAppImagesImpl, this, app_url), consumer); |
116 } | 117 } |
117 | 118 |
118 //////////////////////////////////////////////////////////////////////////////// | 119 //////////////////////////////////////////////////////////////////////////////// |
119 | 120 |
120 WebDataService::WebDataService() | 121 WebDataService::WebDataService() |
121 : WebDataServiceBase(NULL, ProfileErrorCallback(), | 122 : WebDataServiceBase( |
| 123 NULL, ProfileErrorCallback(), |
122 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI)) { | 124 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI)) { |
123 } | 125 } |
124 | 126 |
125 WebDataService::~WebDataService() { | 127 WebDataService::~WebDataService() { |
126 } | 128 } |
127 | 129 |
128 //////////////////////////////////////////////////////////////////////////////// | 130 //////////////////////////////////////////////////////////////////////////////// |
129 // | 131 // |
130 // Keywords implementation. | 132 // Keywords implementation. |
131 // | 133 // |
132 //////////////////////////////////////////////////////////////////////////////// | 134 //////////////////////////////////////////////////////////////////////////////// |
133 | 135 |
134 WebDatabase::State WebDataService::AddKeywordImpl( | 136 WebDatabase::State WebDataService::AddKeywordImpl( |
135 const TemplateURLData& data, WebDatabase* db) { | 137 const TemplateURLData& data, WebDatabase* db) { |
136 KeywordTable::FromWebDatabase(db)->AddKeyword(data); | 138 return KeywordTable::FromWebDatabase(db)->AddKeyword(data) ? |
137 return WebDatabase::COMMIT_NEEDED; | 139 WebDatabase::COMMIT_NEEDED : WebDatabase::COMMIT_NOT_NEEDED; |
138 } | 140 } |
139 | 141 |
140 WebDatabase::State WebDataService::RemoveKeywordImpl( | 142 WebDatabase::State WebDataService::RemoveKeywordImpl( |
141 TemplateURLID id, WebDatabase* db) { | 143 TemplateURLID id, WebDatabase* db) { |
142 DCHECK(id); | 144 DCHECK(id); |
143 KeywordTable::FromWebDatabase(db)->RemoveKeyword(id); | 145 return KeywordTable::FromWebDatabase(db)->RemoveKeyword(id) ? |
144 return WebDatabase::COMMIT_NEEDED; | 146 WebDatabase::COMMIT_NEEDED : WebDatabase::COMMIT_NOT_NEEDED; |
145 } | 147 } |
146 | 148 |
147 WebDatabase::State WebDataService::UpdateKeywordImpl( | 149 WebDatabase::State WebDataService::UpdateKeywordImpl( |
148 const TemplateURLData& data, WebDatabase* db) { | 150 const TemplateURLData& data, WebDatabase* db) { |
149 if (!KeywordTable::FromWebDatabase(db)->UpdateKeyword(data)) { | 151 return KeywordTable::FromWebDatabase(db)->UpdateKeyword(data) ? |
150 NOTREACHED(); | 152 WebDatabase::COMMIT_NEEDED : WebDatabase::COMMIT_NOT_NEEDED; |
151 return WebDatabase::COMMIT_NOT_NEEDED; | |
152 } | |
153 return WebDatabase::COMMIT_NEEDED; | |
154 } | 153 } |
155 | 154 |
156 scoped_ptr<WDTypedResult> WebDataService::GetKeywordsImpl(WebDatabase* db) { | 155 scoped_ptr<WDTypedResult> WebDataService::GetKeywordsImpl(WebDatabase* db) { |
| 156 scoped_ptr<WDTypedResult> result_ptr; |
157 WDKeywordsResult result; | 157 WDKeywordsResult result; |
158 KeywordTable::FromWebDatabase(db)->GetKeywords(&result.keywords); | 158 if (KeywordTable::FromWebDatabase(db)->GetKeywords(&result.keywords)) { |
159 result.default_search_provider_id = | 159 result.default_search_provider_id = |
160 KeywordTable::FromWebDatabase(db)->GetDefaultSearchProviderID(); | 160 KeywordTable::FromWebDatabase(db)->GetDefaultSearchProviderID(); |
161 result.builtin_keyword_version = | 161 result.builtin_keyword_version = |
162 KeywordTable::FromWebDatabase(db)->GetBuiltinKeywordVersion(); | 162 KeywordTable::FromWebDatabase(db)->GetBuiltinKeywordVersion(); |
163 return scoped_ptr<WDTypedResult>( | 163 result_ptr.reset(new WDResult<WDKeywordsResult>(KEYWORDS_RESULT, result)); |
164 new WDResult<WDKeywordsResult>(KEYWORDS_RESULT, result)); | 164 } |
| 165 return result_ptr.Pass(); |
165 } | 166 } |
166 | 167 |
167 WebDatabase::State WebDataService::SetDefaultSearchProviderImpl( | 168 WebDatabase::State WebDataService::SetDefaultSearchProviderImpl( |
168 TemplateURLID id, WebDatabase* db) { | 169 TemplateURLID id, WebDatabase* db) { |
169 if (!KeywordTable::FromWebDatabase(db)->SetDefaultSearchProviderID(id)) { | 170 return KeywordTable::FromWebDatabase(db)->SetDefaultSearchProviderID(id) ? |
170 NOTREACHED(); | 171 WebDatabase::COMMIT_NEEDED : WebDatabase::COMMIT_NOT_NEEDED; |
171 return WebDatabase::COMMIT_NOT_NEEDED; | |
172 } | |
173 return WebDatabase::COMMIT_NEEDED; | |
174 } | 172 } |
175 | 173 |
176 WebDatabase::State WebDataService::SetBuiltinKeywordVersionImpl( | 174 WebDatabase::State WebDataService::SetBuiltinKeywordVersionImpl( |
177 int version, WebDatabase* db) { | 175 int version, WebDatabase* db) { |
178 if (!KeywordTable::FromWebDatabase(db)->SetBuiltinKeywordVersion(version)) { | 176 return KeywordTable::FromWebDatabase(db)->SetBuiltinKeywordVersion(version) ? |
179 NOTREACHED(); | 177 WebDatabase::COMMIT_NEEDED : WebDatabase::COMMIT_NOT_NEEDED; |
180 return WebDatabase::COMMIT_NOT_NEEDED; | |
181 } | |
182 return WebDatabase::COMMIT_NEEDED; | |
183 } | 178 } |
184 | 179 |
185 //////////////////////////////////////////////////////////////////////////////// | 180 //////////////////////////////////////////////////////////////////////////////// |
186 // | 181 // |
187 // Web Apps implementation. | 182 // Web Apps implementation. |
188 // | 183 // |
189 //////////////////////////////////////////////////////////////////////////////// | 184 //////////////////////////////////////////////////////////////////////////////// |
190 | 185 |
191 WebDatabase::State WebDataService::SetWebAppImageImpl( | 186 WebDatabase::State WebDataService::SetWebAppImageImpl( |
192 const GURL& app_url, const SkBitmap& image, WebDatabase* db) { | 187 const GURL& app_url, const SkBitmap& image, WebDatabase* db) { |
(...skipping 16 matching lines...) Expand all Loading... |
209 | 204 |
210 scoped_ptr<WDTypedResult> WebDataService::GetWebAppImagesImpl( | 205 scoped_ptr<WDTypedResult> WebDataService::GetWebAppImagesImpl( |
211 const GURL& app_url, WebDatabase* db) { | 206 const GURL& app_url, WebDatabase* db) { |
212 WDAppImagesResult result; | 207 WDAppImagesResult result; |
213 result.has_all_images = | 208 result.has_all_images = |
214 WebAppsTable::FromWebDatabase(db)->GetWebAppHasAllImages(app_url); | 209 WebAppsTable::FromWebDatabase(db)->GetWebAppHasAllImages(app_url); |
215 WebAppsTable::FromWebDatabase(db)->GetWebAppImages(app_url, &result.images); | 210 WebAppsTable::FromWebDatabase(db)->GetWebAppImages(app_url, &result.images); |
216 return scoped_ptr<WDTypedResult>( | 211 return scoped_ptr<WDTypedResult>( |
217 new WDResult<WDAppImagesResult>(WEB_APP_IMAGES, result)); | 212 new WDResult<WDAppImagesResult>(WEB_APP_IMAGES, result)); |
218 } | 213 } |
OLD | NEW |