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

Side by Side Diff: chrome/browser/history/chrome_history_client.cc

Issue 1198373002: Split HistoryClient in two objects (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@1192403002
Patch Set: Add comments in ChromeHistoryBackendClient Created 5 years, 6 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 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/history/chrome_history_client.h" 5 #include "chrome/browser/history/chrome_history_client.h"
6 6
7 #include "base/logging.h" 7 #include "chrome/browser/history/chrome_history_backend_client.h"
8 #include "chrome/browser/history/history_utils.h" 8 #include "chrome/browser/history/history_utils.h"
9 #include "chrome/browser/ui/profile_error_dialog.h" 9 #include "chrome/browser/ui/profile_error_dialog.h"
10 #include "chrome/common/chrome_version_info.h" 10 #include "chrome/common/chrome_version_info.h"
11 #include "chrome/grit/chromium_strings.h" 11 #include "chrome/grit/chromium_strings.h"
12 #include "chrome/grit/generated_resources.h" 12 #include "chrome/grit/generated_resources.h"
13 #include "components/bookmarks/browser/bookmark_model.h" 13 #include "components/bookmarks/browser/bookmark_model.h"
14 14
15 #if defined(OS_ANDROID)
16 #include "base/files/file_path.h"
17 #include "chrome/browser/history/android/android_provider_backend.h"
18 #include "components/history/core/browser/history_backend.h"
19 #endif
20
21 #if defined(OS_ANDROID)
22 namespace {
23
24 const base::FilePath::CharType kAndroidCacheFilename[] =
25 FILE_PATH_LITERAL("AndroidCache");
26
27 base::FilePath GetAndroidCacheFileName(const base::FilePath& history_dir) {
28 return history_dir.Append(kAndroidCacheFilename);
29 }
30
31 } // namespace
32 #endif
33
34 ChromeHistoryClient::ChromeHistoryClient( 15 ChromeHistoryClient::ChromeHistoryClient(
35 bookmarks::BookmarkModel* bookmark_model) 16 bookmarks::BookmarkModel* bookmark_model)
36 : bookmark_model_(bookmark_model) { 17 : bookmark_model_(bookmark_model) {
37 } 18 }
38 19
39 ChromeHistoryClient::~ChromeHistoryClient() { 20 ChromeHistoryClient::~ChromeHistoryClient() {
40 } 21 }
41 22
42 void ChromeHistoryClient::Shutdown() { 23 void ChromeHistoryClient::Shutdown() {
43 // It's possible that bookmarks haven't loaded and history is waiting for 24 // It's possible that bookmarks haven't loaded and history is waiting for
44 // bookmarks to complete loading. In such a situation history can't shutdown 25 // bookmarks to complete loading. In such a situation history can't shutdown
45 // (meaning if we invoked HistoryService::Cleanup now, we would deadlock). To 26 // (meaning if we invoked HistoryService::Cleanup now, we would deadlock). To
46 // break the deadlock we tell BookmarkModel it's about to be deleted so that 27 // break the deadlock we tell BookmarkModel it's about to be deleted so that
47 // it can release the signal history is waiting on, allowing history to 28 // it can release the signal history is waiting on, allowing history to
48 // shutdown (HistoryService::Cleanup to complete). In such a scenario history 29 // shutdown (HistoryService::Cleanup to complete). In such a scenario history
49 // sees an incorrect view of bookmarks, but it's better than a deadlock. 30 // sees an incorrect view of bookmarks, but it's better than a deadlock.
50 if (bookmark_model_) 31 if (bookmark_model_)
51 bookmark_model_->Shutdown(); 32 bookmark_model_->Shutdown();
52 } 33 }
53 34
54 void ChromeHistoryClient::BlockUntilBookmarksLoaded() {
55 if (bookmark_model_)
56 bookmark_model_->BlockTillLoaded();
57 }
58
59 bool ChromeHistoryClient::IsBookmarked(const GURL& url) {
60 return bookmark_model_ && bookmark_model_->IsBookmarked(url);
61 }
62
63 void ChromeHistoryClient::GetBookmarks(
64 std::vector<history::URLAndTitle>* bookmarks) {
65 if (!bookmark_model_)
66 return;
67
68 std::vector<bookmarks::BookmarkModel::URLAndTitle> bookmarks_url_and_title;
69 bookmark_model_->GetBookmarks(&bookmarks_url_and_title);
70
71 bookmarks->reserve(bookmarks->size() + bookmarks_url_and_title.size());
72 for (size_t i = 0; i < bookmarks_url_and_title.size(); ++i) {
73 history::URLAndTitle value = {
74 bookmarks_url_and_title[i].url,
75 bookmarks_url_and_title[i].title,
76 };
77 bookmarks->push_back(value);
78 }
79 }
80
81 bool ChromeHistoryClient::CanAddURL(const GURL& url) { 35 bool ChromeHistoryClient::CanAddURL(const GURL& url) {
82 return CanAddURLToHistory(url); 36 return CanAddURLToHistory(url);
83 } 37 }
84 38
85 void ChromeHistoryClient::NotifyProfileError(sql::InitStatus init_status) { 39 void ChromeHistoryClient::NotifyProfileError(sql::InitStatus init_status) {
86 ShowProfileErrorDialog( 40 ShowProfileErrorDialog(
87 PROFILE_ERROR_HISTORY, 41 PROFILE_ERROR_HISTORY,
88 (init_status == sql::INIT_FAILURE) ? 42 (init_status == sql::INIT_FAILURE) ?
89 IDS_COULDNT_OPEN_PROFILE_ERROR : IDS_PROFILE_TOO_NEW_ERROR); 43 IDS_COULDNT_OPEN_PROFILE_ERROR : IDS_PROFILE_TOO_NEW_ERROR);
90 } 44 }
91 45
92 bool ChromeHistoryClient::ShouldReportDatabaseError() { 46 scoped_ptr<history::HistoryBackendClient>
93 // TODO(shess): For now, don't report on beta or stable so as not to 47 ChromeHistoryClient::CreateBackendClient() {
94 // overwhelm the crash server. Once the big fish are fried, 48 return make_scoped_ptr(new ChromeHistoryBackendClient(bookmark_model_));
95 // consider reporting at a reduced rate on the bigger channels.
96 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
97 return channel != chrome::VersionInfo::CHANNEL_STABLE &&
98 channel != chrome::VersionInfo::CHANNEL_BETA;
99 } 49 }
100
101 #if defined(OS_ANDROID)
102 void ChromeHistoryClient::OnHistoryBackendInitialized(
103 history::HistoryBackend* history_backend,
104 history::HistoryDatabase* history_database,
105 history::ThumbnailDatabase* thumbnail_database,
106 const base::FilePath& history_dir) {
107 if (thumbnail_database) {
108 DCHECK(history_backend);
109 history_backend->SetUserData(
110 history::AndroidProviderBackend::GetUserDataKey(),
111 new history::AndroidProviderBackend(
112 GetAndroidCacheFileName(history_dir), history_database,
113 thumbnail_database, this, history_backend));
114 }
115 }
116
117 void ChromeHistoryClient::OnHistoryBackendDestroyed(
118 history::HistoryBackend* history_backend,
119 const base::FilePath& history_dir) {
120 sql::Connection::Delete(GetAndroidCacheFileName(history_dir));
121 }
122 #endif
OLDNEW
« no previous file with comments | « chrome/browser/history/chrome_history_client.h ('k') | chrome/browser/sync/profile_sync_service_typed_url_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698