Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: chrome/browser/autocomplete/shortcuts_backend.cc

Issue 290043003: Revert of Use ExtensionRegistryObserver (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/autocomplete/shortcuts_backend.h" 5 #include "chrome/browser/autocomplete/shortcuts_backend.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 10 matching lines...) Expand all
21 #include "chrome/browser/history/history_notifications.h" 21 #include "chrome/browser/history/history_notifications.h"
22 #include "chrome/browser/history/history_service.h" 22 #include "chrome/browser/history/history_service.h"
23 #include "chrome/browser/history/shortcuts_database.h" 23 #include "chrome/browser/history/shortcuts_database.h"
24 #include "chrome/browser/omnibox/omnibox_log.h" 24 #include "chrome/browser/omnibox/omnibox_log.h"
25 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/common/autocomplete_match_type.h" 26 #include "chrome/common/autocomplete_match_type.h"
27 #include "chrome/common/chrome_constants.h" 27 #include "chrome/common/chrome_constants.h"
28 #include "content/public/browser/browser_thread.h" 28 #include "content/public/browser/browser_thread.h"
29 #include "content/public/browser/notification_details.h" 29 #include "content/public/browser/notification_details.h"
30 #include "content/public/browser/notification_source.h" 30 #include "content/public/browser/notification_source.h"
31 #include "extensions/browser/extension_registry.h"
32 #include "extensions/common/extension.h" 31 #include "extensions/common/extension.h"
33 32
34 using content::BrowserThread; 33 using content::BrowserThread;
35 34
36 namespace { 35 namespace {
37 36
38 // Takes Match classification vector and removes all matched positions, 37 // Takes Match classification vector and removes all matched positions,
39 // compacting repetitions if necessary. 38 // compacting repetitions if necessary.
40 std::string StripMatchMarkers(const ACMatchClassifications& matches) { 39 std::string StripMatchMarkers(const ACMatchClassifications& matches) {
41 ACMatchClassifications unmatched; 40 ACMatchClassifications unmatched;
(...skipping 25 matching lines...) Expand all
67 } 66 }
68 67
69 } // namespace 68 } // namespace
70 69
71 70
72 // ShortcutsBackend ----------------------------------------------------------- 71 // ShortcutsBackend -----------------------------------------------------------
73 72
74 ShortcutsBackend::ShortcutsBackend(Profile* profile, bool suppress_db) 73 ShortcutsBackend::ShortcutsBackend(Profile* profile, bool suppress_db)
75 : profile_(profile), 74 : profile_(profile),
76 current_state_(NOT_INITIALIZED), 75 current_state_(NOT_INITIALIZED),
77 extension_registry_observer_(this),
78 no_db_access_(suppress_db) { 76 no_db_access_(suppress_db) {
79 if (!suppress_db) { 77 if (!suppress_db) {
80 db_ = new history::ShortcutsDatabase( 78 db_ = new history::ShortcutsDatabase(
81 profile->GetPath().Append(chrome::kShortcutsDatabaseName)); 79 profile->GetPath().Append(chrome::kShortcutsDatabaseName));
82 } 80 }
83 // |profile| can be NULL in tests. 81 // |profile| can be NULL in tests.
84 if (profile) { 82 if (profile) {
85 notification_registrar_.Add( 83 notification_registrar_.Add(
84 this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
85 content::Source<Profile>(profile));
86 notification_registrar_.Add(
86 this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, 87 this, chrome::NOTIFICATION_HISTORY_URLS_DELETED,
87 content::Source<Profile>(profile)); 88 content::Source<Profile>(profile));
88 extension_registry_observer_.Add(
89 extensions::ExtensionRegistry::Get(profile));
90 } 89 }
91 } 90 }
92 91
93 bool ShortcutsBackend::Init() { 92 bool ShortcutsBackend::Init() {
94 if (current_state_ != NOT_INITIALIZED) 93 if (current_state_ != NOT_INITIALIZED)
95 return false; 94 return false;
96 95
97 if (no_db_access_) { 96 if (no_db_access_) {
98 current_state_ = INITIALIZED; 97 current_state_ = INITIALIZED;
99 return true; 98 return true;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 160
162 void ShortcutsBackend::ShutdownOnUIThread() { 161 void ShortcutsBackend::ShutdownOnUIThread() {
163 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) || 162 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) ||
164 BrowserThread::CurrentlyOn(BrowserThread::UI)); 163 BrowserThread::CurrentlyOn(BrowserThread::UI));
165 notification_registrar_.RemoveAll(); 164 notification_registrar_.RemoveAll();
166 } 165 }
167 166
168 void ShortcutsBackend::Observe(int type, 167 void ShortcutsBackend::Observe(int type,
169 const content::NotificationSource& source, 168 const content::NotificationSource& source,
170 const content::NotificationDetails& details) { 169 const content::NotificationDetails& details) {
170 if (!initialized())
171 return;
172
173 if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED) {
174 // When an extension is unloaded, we want to remove any Shortcuts associated
175 // with it.
176 DeleteShortcutsWithURL(content::Details<extensions::UnloadedExtensionInfo>(
177 details)->extension->url(), false);
178 return;
179 }
180
171 DCHECK_EQ(chrome::NOTIFICATION_HISTORY_URLS_DELETED, type); 181 DCHECK_EQ(chrome::NOTIFICATION_HISTORY_URLS_DELETED, type);
172 const history::URLsDeletedDetails* deleted_details = 182 const history::URLsDeletedDetails* deleted_details =
173 content::Details<const history::URLsDeletedDetails>(details).ptr(); 183 content::Details<const history::URLsDeletedDetails>(details).ptr();
174 if (deleted_details->all_history) { 184 if (deleted_details->all_history) {
175 DeleteAllShortcuts(); 185 DeleteAllShortcuts();
176 return; 186 return;
177 } 187 }
178 188
179 const history::URLRows& rows(deleted_details->rows); 189 const history::URLRows& rows(deleted_details->rows);
180 history::ShortcutsDatabase::ShortcutIDs shortcut_ids; 190 history::ShortcutsDatabase::ShortcutIDs shortcut_ids;
181 for (GuidMap::const_iterator it(guid_map_.begin()); it != guid_map_.end(); 191 for (GuidMap::const_iterator it(guid_map_.begin()); it != guid_map_.end();
182 ++it) { 192 ++it) {
183 if (std::find_if( 193 if (std::find_if(
184 rows.begin(), rows.end(), history::URLRow::URLRowHasURL( 194 rows.begin(), rows.end(), history::URLRow::URLRowHasURL(
185 it->second->second.match_core.destination_url)) != rows.end()) 195 it->second->second.match_core.destination_url)) != rows.end())
186 shortcut_ids.push_back(it->first); 196 shortcut_ids.push_back(it->first);
187 } 197 }
188 DeleteShortcutsWithIDs(shortcut_ids); 198 DeleteShortcutsWithIDs(shortcut_ids);
189 } 199 }
190 200
191 void ShortcutsBackend::OnExtensionUnloaded(
192 content::BrowserContext* browser_context,
193 const extensions::Extension* extension,
194 extensions::UnloadedExtensionInfo::Reason reason) {
195 if (!initialized())
196 return;
197
198 // When an extension is unloaded, we want to remove any Shortcuts associated
199 // with it.
200 DeleteShortcutsWithURL(extension->url(), false);
201 }
202
203 void ShortcutsBackend::InitInternal() { 201 void ShortcutsBackend::InitInternal() {
204 DCHECK(current_state_ == INITIALIZING); 202 DCHECK(current_state_ == INITIALIZING);
205 db_->Init(); 203 db_->Init();
206 history::ShortcutsDatabase::GuidToShortcutMap shortcuts; 204 history::ShortcutsDatabase::GuidToShortcutMap shortcuts;
207 db_->LoadShortcuts(&shortcuts); 205 db_->LoadShortcuts(&shortcuts);
208 temp_shortcuts_map_.reset(new ShortcutMap); 206 temp_shortcuts_map_.reset(new ShortcutMap);
209 temp_guid_map_.reset(new GuidMap); 207 temp_guid_map_.reset(new GuidMap);
210 for (history::ShortcutsDatabase::GuidToShortcutMap::const_iterator it( 208 for (history::ShortcutsDatabase::GuidToShortcutMap::const_iterator it(
211 shortcuts.begin()); it != shortcuts.end(); ++it) { 209 shortcuts.begin()); it != shortcuts.end(); ++it) {
212 (*temp_guid_map_)[it->first] = temp_shortcuts_map_->insert( 210 (*temp_guid_map_)[it->first] = temp_shortcuts_map_->insert(
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 guid_map_.clear(); 314 guid_map_.clear();
317 FOR_EACH_OBSERVER(ShortcutsBackendObserver, observer_list_, 315 FOR_EACH_OBSERVER(ShortcutsBackendObserver, observer_list_,
318 OnShortcutsChanged()); 316 OnShortcutsChanged());
319 return no_db_access_ || 317 return no_db_access_ ||
320 BrowserThread::PostTask( 318 BrowserThread::PostTask(
321 BrowserThread::DB, FROM_HERE, 319 BrowserThread::DB, FROM_HERE,
322 base::Bind(base::IgnoreResult( 320 base::Bind(base::IgnoreResult(
323 &history::ShortcutsDatabase::DeleteAllShortcuts), 321 &history::ShortcutsDatabase::DeleteAllShortcuts),
324 db_.get())); 322 db_.get()));
325 } 323 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/shortcuts_backend.h ('k') | chrome/browser/autocomplete/shortcuts_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698