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

Side by Side Diff: chrome/browser/history/in_memory_history_backend.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 (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/history/in_memory_history_backend.h" 5 #include "chrome/browser/history/in_memory_history_backend.h"
6 6
7 #include <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/chrome_notification_types.h" 14 #include "chrome/browser/chrome_notification_types.h"
15 #include "chrome/browser/history/history_notifications.h" 15 #include "chrome/browser/history/history_notifications.h"
16 #include "chrome/browser/history/history_service.h" 16 #include "chrome/browser/history/history_service.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "components/history/core/browser/in_memory_database.h" 18 #include "components/history/core/browser/in_memory_database.h"
19 #include "components/history/core/browser/url_database.h" 19 #include "components/history/core/browser/url_database.h"
20 #include "content/public/browser/notification_details.h" 20 #include "content/public/browser/notification_details.h"
21 #include "content/public/browser/notification_source.h" 21 #include "content/public/browser/notification_source.h"
22 22
23 namespace history { 23 namespace history {
24 24
25 InMemoryHistoryBackend::InMemoryHistoryBackend() 25 InMemoryHistoryBackend::InMemoryHistoryBackend()
26 : profile_(nullptr), history_service_(nullptr) { 26 : profile_(nullptr),
27 history_service_observer_(this),
28 history_service_(nullptr) {
27 } 29 }
28 30
29 InMemoryHistoryBackend::~InMemoryHistoryBackend() { 31 InMemoryHistoryBackend::~InMemoryHistoryBackend() {
30 if (history_service_)
31 history_service_->RemoveObserver(this);
32 } 32 }
33 33
34 bool InMemoryHistoryBackend::Init(const base::FilePath& history_filename) { 34 bool InMemoryHistoryBackend::Init(const base::FilePath& history_filename) {
35 db_.reset(new InMemoryDatabase); 35 db_.reset(new InMemoryDatabase);
36 return db_->InitFromDisk(history_filename); 36 return db_->InitFromDisk(history_filename);
37 } 37 }
38 38
39 void InMemoryHistoryBackend::AttachToHistoryService( 39 void InMemoryHistoryBackend::AttachToHistoryService(
40 Profile* profile, 40 Profile* profile,
41 HistoryService* history_service) { 41 HistoryService* history_service) {
42 if (!db_) { 42 if (!db_) {
43 NOTREACHED(); 43 NOTREACHED();
44 return; 44 return;
45 } 45 }
46 46
47 profile_ = profile;
48
47 DCHECK(history_service); 49 DCHECK(history_service);
50 history_service_observer_.Add(history_service);
48 history_service_ = history_service; 51 history_service_ = history_service;
49 history_service_->AddObserver(this);
50
51 profile_ = profile;
52 52
53 // TODO(evanm): this is currently necessitated by generate_profile, which 53 // TODO(evanm): this is currently necessitated by generate_profile, which
54 // runs without a browser process. generate_profile should really create 54 // runs without a browser process. generate_profile should really create
55 // a browser process, at which point this check can then be nuked. 55 // a browser process, at which point this check can then be nuked.
56 if (!g_browser_process) 56 if (!g_browser_process)
57 return; 57 return;
58 58
59 // Register for the notifications we care about. 59 // Register for the notifications we care about.
60 // We only want notifications for the associated profile. 60 // We only want notifications for the associated profile.
61 content::Source<Profile> source(profile_); 61 content::Source<Profile> source(profile_);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 } 150 }
151 151
152 void InMemoryHistoryBackend::OnKeywordSearchTermDeleted( 152 void InMemoryHistoryBackend::OnKeywordSearchTermDeleted(
153 const KeywordSearchDeletedDetails& details) { 153 const KeywordSearchDeletedDetails& details) {
154 // For simplicity, this will not remove the corresponding URLRow, but this is 154 // For simplicity, this will not remove the corresponding URLRow, but this is
155 // okay, as the main database does not do so either. 155 // okay, as the main database does not do so either.
156 db_->DeleteKeywordSearchTermForURL(details.url_row_id); 156 db_->DeleteKeywordSearchTermForURL(details.url_row_id);
157 } 157 }
158 158
159 } // namespace history 159 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698