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

Side by Side Diff: chrome/browser/extensions/api/bookmarks/bookmarks_api.cc

Issue 306293006: Introduce ChromeBookmarkClientFactory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@364865
Patch Set: Add missing dependency in components/policy/policy_browser.gypi Created 6 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 (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/extensions/api/bookmarks/bookmarks_api.h" 5 #include "chrome/browser/extensions/api/bookmarks/bookmarks_api.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/i18n/file_util_icu.h" 9 #include "base/i18n/file_util_icu.h"
10 #include "base/i18n/time_formatting.h" 10 #include "base/i18n/time_formatting.h"
11 #include "base/json/json_writer.h" 11 #include "base/json/json_writer.h"
12 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/path_service.h" 14 #include "base/path_service.h"
15 #include "base/prefs/pref_service.h" 15 #include "base/prefs/pref_service.h"
16 #include "base/sha1.h" 16 #include "base/sha1.h"
17 #include "base/stl_util.h" 17 #include "base/stl_util.h"
18 #include "base/strings/string16.h" 18 #include "base/strings/string16.h"
19 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
21 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
22 #include "base/time/time.h" 22 #include "base/time/time.h"
23 #include "chrome/browser/bookmarks/bookmark_html_writer.h" 23 #include "chrome/browser/bookmarks/bookmark_html_writer.h"
24 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 24 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
25 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" 25 #include "chrome/browser/bookmarks/chrome_bookmark_client.h"
26 #include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h"
26 #include "chrome/browser/chrome_notification_types.h" 27 #include "chrome/browser/chrome_notification_types.h"
27 #include "chrome/browser/extensions/api/bookmarks/bookmark_api_constants.h" 28 #include "chrome/browser/extensions/api/bookmarks/bookmark_api_constants.h"
28 #include "chrome/browser/extensions/api/bookmarks/bookmark_api_helpers.h" 29 #include "chrome/browser/extensions/api/bookmarks/bookmark_api_helpers.h"
29 #include "chrome/browser/importer/external_process_importer_host.h" 30 #include "chrome/browser/importer/external_process_importer_host.h"
30 #include "chrome/browser/importer/importer_uma.h" 31 #include "chrome/browser/importer/importer_uma.h"
31 #include "chrome/browser/platform_util.h" 32 #include "chrome/browser/platform_util.h"
32 #include "chrome/browser/profiles/profile.h" 33 #include "chrome/browser/profiles/profile.h"
33 #include "chrome/browser/ui/chrome_select_file_policy.h" 34 #include "chrome/browser/ui/chrome_select_file_policy.h"
34 #include "chrome/browser/ui/host_desktop.h" 35 #include "chrome/browser/ui/host_desktop.h"
35 #include "chrome/common/chrome_paths.h" 36 #include "chrome/common/chrome_paths.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 if (success) { 112 if (success) {
112 content::NotificationService::current()->Notify( 113 content::NotificationService::current()->Notify(
113 chrome::NOTIFICATION_EXTENSION_BOOKMARKS_API_INVOKED, 114 chrome::NOTIFICATION_EXTENSION_BOOKMARKS_API_INVOKED,
114 content::Source<const Extension>(GetExtension()), 115 content::Source<const Extension>(GetExtension()),
115 content::Details<const BookmarksFunction>(this)); 116 content::Details<const BookmarksFunction>(this));
116 } 117 }
117 SendResponse(success); 118 SendResponse(success);
118 return true; 119 return true;
119 } 120 }
120 121
122 BookmarkModel* BookmarksFunction::GetBookmarkModel() {
123 return BookmarkModelFactory::GetForProfile(GetProfile());
124 }
125
121 ChromeBookmarkClient* BookmarksFunction::GetChromeBookmarkClient() { 126 ChromeBookmarkClient* BookmarksFunction::GetChromeBookmarkClient() {
122 return BookmarkModelFactory::GetChromeBookmarkClientForProfile(GetProfile()); 127 return ChromeBookmarkClientFactory::GetForProfile(GetProfile());
123 } 128 }
124 129
125 bool BookmarksFunction::GetBookmarkIdAsInt64(const std::string& id_string, 130 bool BookmarksFunction::GetBookmarkIdAsInt64(const std::string& id_string,
126 int64* id) { 131 int64* id) {
127 if (base::StringToInt64(id_string, id)) 132 if (base::StringToInt64(id_string, id))
128 return true; 133 return true;
129 134
130 error_ = keys::kInvalidIdError; 135 error_ = keys::kInvalidIdError;
131 return false; 136 return false;
132 } 137 }
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 void BookmarksFunction::BookmarkModelLoaded(BookmarkModel* model, 238 void BookmarksFunction::BookmarkModelLoaded(BookmarkModel* model,
234 bool ids_reassigned) { 239 bool ids_reassigned) {
235 model->RemoveObserver(this); 240 model->RemoveObserver(this);
236 RunOnReady(); 241 RunOnReady();
237 Release(); // Balanced in RunOnReady(). 242 Release(); // Balanced in RunOnReady().
238 } 243 }
239 244
240 BookmarkEventRouter::BookmarkEventRouter(Profile* profile) 245 BookmarkEventRouter::BookmarkEventRouter(Profile* profile)
241 : browser_context_(profile), 246 : browser_context_(profile),
242 model_(BookmarkModelFactory::GetForProfile(profile)), 247 model_(BookmarkModelFactory::GetForProfile(profile)),
243 client_( 248 client_(ChromeBookmarkClientFactory::GetForProfile(profile)) {
244 BookmarkModelFactory::GetChromeBookmarkClientForProfile(profile)) {
245 model_->AddObserver(this); 249 model_->AddObserver(this);
246 } 250 }
247 251
248 BookmarkEventRouter::~BookmarkEventRouter() { 252 BookmarkEventRouter::~BookmarkEventRouter() {
249 if (model_) { 253 if (model_) {
250 model_->RemoveObserver(this); 254 model_->RemoveObserver(this);
251 } 255 }
252 } 256 }
253 257
254 void BookmarkEventRouter::DispatchEvent( 258 void BookmarkEventRouter::DispatchEvent(
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 EXTENSION_FUNCTION_VALIDATE(params.get()); 583 EXTENSION_FUNCTION_VALIDATE(params.get());
580 584
581 int64 id; 585 int64 id;
582 if (!GetBookmarkIdAsInt64(params->id, &id)) 586 if (!GetBookmarkIdAsInt64(params->id, &id))
583 return false; 587 return false;
584 588
585 bool recursive = false; 589 bool recursive = false;
586 if (name() == BookmarksRemoveTreeFunction::function_name()) 590 if (name() == BookmarksRemoveTreeFunction::function_name())
587 recursive = true; 591 recursive = true;
588 592
593 BookmarkModel* model = GetBookmarkModel();
589 ChromeBookmarkClient* client = GetChromeBookmarkClient(); 594 ChromeBookmarkClient* client = GetChromeBookmarkClient();
590 if (!bookmark_api_helpers::RemoveNode(client, id, recursive, &error_)) 595 if (!bookmark_api_helpers::RemoveNode(model, client, id, recursive, &error_))
591 return false; 596 return false;
592 597
593 return true; 598 return true;
594 } 599 }
595 600
596 bool BookmarksCreateFunction::RunOnReady() { 601 bool BookmarksCreateFunction::RunOnReady() {
597 if (!EditBookmarksEnabled()) 602 if (!EditBookmarksEnabled())
598 return false; 603 return false;
599 604
600 scoped_ptr<bookmarks::Create::Params> params( 605 scoped_ptr<bookmarks::Create::Params> params(
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 #if !defined(OS_ANDROID) 1045 #if !defined(OS_ANDROID)
1041 // Android does not have support for the standard exporter. 1046 // Android does not have support for the standard exporter.
1042 // TODO(jgreenwald): remove ifdef once extensions are no longer built on 1047 // TODO(jgreenwald): remove ifdef once extensions are no longer built on
1043 // Android. 1048 // Android.
1044 bookmark_html_writer::WriteBookmarks(GetProfile(), path, NULL); 1049 bookmark_html_writer::WriteBookmarks(GetProfile(), path, NULL);
1045 #endif 1050 #endif
1046 Release(); // Balanced in BookmarksIOFunction::SelectFile() 1051 Release(); // Balanced in BookmarksIOFunction::SelectFile()
1047 } 1052 }
1048 1053
1049 } // namespace extensions 1054 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698