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

Side by Side Diff: chrome/browser/search_engines/chrome_template_url_service_client.cc

Issue 573553004: Eliminate NOTIFICATION_HISTORY_LOADED notification (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add ScopedObserver to InMemoryHistoryBackend,PrerenderLocalPredictor,ChromeTemplateURLServiceClient Created 6 years 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/search_engines/chrome_template_url_service_client.h" 5 #include "chrome/browser/search_engines/chrome_template_url_service_client.h"
6 6
7 #include "chrome/browser/history/history_service.h" 7 #include "chrome/browser/history/history_service.h"
8 #include "components/search_engines/template_url_service.h" 8 #include "components/search_engines/template_url_service.h"
9 #include "extensions/common/constants.h" 9 #include "extensions/common/constants.h"
10 10
11 ChromeTemplateURLServiceClient::ChromeTemplateURLServiceClient( 11 ChromeTemplateURLServiceClient::ChromeTemplateURLServiceClient(
12 HistoryService* history_service) 12 HistoryService* history_service)
13 : owner_(NULL), history_service_(history_service) { 13 : owner_(NULL),
14 history_service_observer_(this),
15 history_service_(history_service) {
14 // TODO(sky): bug 1166191. The keywords should be moved into the history 16 // TODO(sky): bug 1166191. The keywords should be moved into the history
15 // db, which will mean we no longer need this notification and the history 17 // db, which will mean we no longer need this notification and the history
16 // backend can handle automatically adding the search terms as the user 18 // backend can handle automatically adding the search terms as the user
17 // navigates. 19 // navigates.
18 if (history_service_) 20 if (history_service_)
19 history_service_->AddObserver(this); 21 history_service_observer_.Add(history_service_);
20 } 22 }
21 23
22 ChromeTemplateURLServiceClient::~ChromeTemplateURLServiceClient() { 24 ChromeTemplateURLServiceClient::~ChromeTemplateURLServiceClient() {
23 } 25 }
24 26
25 void ChromeTemplateURLServiceClient::Shutdown() { 27 void ChromeTemplateURLServiceClient::Shutdown() {
26 // ChromeTemplateURLServiceClient is owned by TemplateURLService which is a 28 // ChromeTemplateURLServiceClient is owned by TemplateURLService which is a
27 // KeyedService with a dependency on HistoryService, thus |history_service_| 29 // KeyedService with a dependency on HistoryService, thus |history_service_|
28 // outlives the ChromeTemplateURLServiceClient. 30 // outlives the ChromeTemplateURLServiceClient.
29 // 31 //
30 // Remove self from |history_service_| observers in the shutdown phase of the 32 // Remove self from |history_service_| observers in the shutdown phase of the
31 // two-phases since KeyedService are not supposed to use a dependend service 33 // two-phases since KeyedService are not supposed to use a dependend service
32 // after the Shutdown call. 34 // after the Shutdown call.
33 if (history_service_) 35 history_service_observer_.RemoveAll();
34 history_service_->RemoveObserver(this);
35 } 36 }
36 37
37 void ChromeTemplateURLServiceClient::SetOwner(TemplateURLService* owner) { 38 void ChromeTemplateURLServiceClient::SetOwner(TemplateURLService* owner) {
38 DCHECK(!owner_); 39 DCHECK(!owner_);
39 owner_ = owner; 40 owner_ = owner;
40 } 41 }
41 42
42 void ChromeTemplateURLServiceClient::DeleteAllSearchTermsForKeyword( 43 void ChromeTemplateURLServiceClient::DeleteAllSearchTermsForKeyword(
43 TemplateURLID id) { 44 TemplateURLID id) {
44 if (history_service_) 45 if (history_service_)
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 DCHECK_EQ(history_service_, history_service); 83 DCHECK_EQ(history_service_, history_service);
83 if (!owner_) 84 if (!owner_)
84 return; 85 return;
85 86
86 TemplateURLService::URLVisitedDetails visited_details; 87 TemplateURLService::URLVisitedDetails visited_details;
87 visited_details.url = row.url(); 88 visited_details.url = row.url();
88 visited_details.is_keyword_transition = 89 visited_details.is_keyword_transition =
89 ui::PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_KEYWORD); 90 ui::PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_KEYWORD);
90 owner_->OnHistoryURLVisited(visited_details); 91 owner_->OnHistoryURLVisited(visited_details);
91 } 92 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698