Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / history / chrome_history_client.cc
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/history/chrome_history_client.h"
6
7 #include "base/logging.h"
8 #include "chrome/browser/ui/profile_error_dialog.h"
9 #include "chrome/common/chrome_version_info.h"
10 #include "components/bookmarks/browser/bookmark_model.h"
11 #include "grit/chromium_strings.h"
12 #include "grit/generated_resources.h"
13
14 ChromeHistoryClient::ChromeHistoryClient(BookmarkModel* bookmark_model)
15     : bookmark_model_(bookmark_model) {
16   DCHECK(bookmark_model_);
17 }
18
19 void ChromeHistoryClient::BlockUntilBookmarksLoaded() {
20   bookmark_model_->BlockTillLoaded();
21 }
22
23 bool ChromeHistoryClient::IsBookmarked(const GURL& url) {
24   return bookmark_model_->IsBookmarked(url);
25 }
26
27 void ChromeHistoryClient::GetBookmarks(
28     std::vector<history::URLAndTitle>* bookmarks) {
29   std::vector<BookmarkModel::URLAndTitle> bookmarks_url_and_title;
30   bookmark_model_->GetBookmarks(&bookmarks_url_and_title);
31
32   bookmarks->reserve(bookmarks->size() + bookmarks_url_and_title.size());
33   for (size_t i = 0; i < bookmarks_url_and_title.size(); ++i) {
34     history::URLAndTitle value = {
35       bookmarks_url_and_title[i].url,
36       bookmarks_url_and_title[i].title,
37     };
38     bookmarks->push_back(value);
39   }
40 }
41
42 void ChromeHistoryClient::NotifyProfileError(sql::InitStatus init_status) {
43   ShowProfileErrorDialog(
44       PROFILE_ERROR_HISTORY,
45       (init_status == sql::INIT_FAILURE) ?
46       IDS_COULDNT_OPEN_PROFILE_ERROR : IDS_PROFILE_TOO_NEW_ERROR);
47 }
48
49 bool ChromeHistoryClient::ShouldReportDatabaseError() {
50   // TODO(shess): For now, don't report on beta or stable so as not to
51   // overwhelm the crash server.  Once the big fish are fried,
52   // consider reporting at a reduced rate on the bigger channels.
53   chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
54   return channel != chrome::VersionInfo::CHANNEL_STABLE &&
55       channel != chrome::VersionInfo::CHANNEL_BETA;
56 }
57
58 void ChromeHistoryClient::Shutdown() {
59   // It's possible that bookmarks haven't loaded and history is waiting for
60   // bookmarks to complete loading. In such a situation history can't shutdown
61   // (meaning if we invoked HistoryService::Cleanup now, we would deadlock). To
62   // break the deadlock we tell BookmarkModel it's about to be deleted so that
63   // it can release the signal history is waiting on, allowing history to
64   // shutdown (HistoryService::Cleanup to complete). In such a scenario history
65   // sees an incorrect view of bookmarks, but it's better than a deadlock.
66   bookmark_model_->Shutdown();
67 }