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

Side by Side Diff: chrome/browser/bookmarks/bookmark_extension_api.cc

Issue 10821097: Removing instances of profile_->GetBookmarkModel() as part of converting BookmarkModel to a PKS. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 4 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 | Annotate | Revision Log
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/bookmarks/bookmark_extension_api.h" 5 #include "chrome/browser/bookmarks/bookmark_extension_api.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_path.h" 8 #include "base/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/path_service.h" 12 #include "base/path_service.h"
13 #include "base/sha1.h" 13 #include "base/sha1.h"
14 #include "base/stl_util.h" 14 #include "base/stl_util.h"
15 #include "base/string16.h" 15 #include "base/string16.h"
16 #include "base/string_number_conversions.h" 16 #include "base/string_number_conversions.h"
17 #include "base/string_util.h" 17 #include "base/string_util.h"
18 #include "base/time.h" 18 #include "base/time.h"
19 #include "base/utf_string_conversions.h" 19 #include "base/utf_string_conversions.h"
20 #include "chrome/browser/bookmarks/bookmark_codec.h" 20 #include "chrome/browser/bookmarks/bookmark_codec.h"
21 #include "chrome/browser/bookmarks/bookmark_extension_api_constants.h" 21 #include "chrome/browser/bookmarks/bookmark_extension_api_constants.h"
22 #include "chrome/browser/bookmarks/bookmark_extension_helpers.h" 22 #include "chrome/browser/bookmarks/bookmark_extension_helpers.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.h" 24 #include "chrome/browser/bookmarks/bookmark_model.h"
25 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
25 #include "chrome/browser/bookmarks/bookmark_utils.h" 26 #include "chrome/browser/bookmarks/bookmark_utils.h"
26 #include "chrome/browser/extensions/event_router.h" 27 #include "chrome/browser/extensions/event_router.h"
27 #include "chrome/browser/extensions/extension_function_dispatcher.h" 28 #include "chrome/browser/extensions/extension_function_dispatcher.h"
28 #include "chrome/browser/extensions/extensions_quota_service.h" 29 #include "chrome/browser/extensions/extensions_quota_service.h"
29 #include "chrome/browser/importer/importer_data_types.h" 30 #include "chrome/browser/importer/importer_data_types.h"
30 #include "chrome/browser/importer/importer_host.h" 31 #include "chrome/browser/importer/importer_host.h"
31 #include "chrome/browser/prefs/pref_service.h" 32 #include "chrome/browser/prefs/pref_service.h"
32 #include "chrome/browser/profiles/profile.h" 33 #include "chrome/browser/profiles/profile.h"
33 #include "chrome/browser/ui/browser_list.h" 34 #include "chrome/browser/ui/browser_list.h"
34 #include "chrome/browser/ui/chrome_select_file_policy.h" 35 #include "chrome/browser/ui/chrome_select_file_policy.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 file_util::ReplaceIllegalCharactersInPath(&filename, '_'); 77 file_util::ReplaceIllegalCharactersInPath(&filename, '_');
77 78
78 FilePath default_path; 79 FilePath default_path;
79 PathService::Get(chrome::DIR_USER_DOCUMENTS, &default_path); 80 PathService::Get(chrome::DIR_USER_DOCUMENTS, &default_path);
80 return default_path.Append(filename); 81 return default_path.Append(filename);
81 } 82 }
82 83
83 } // namespace 84 } // namespace
84 85
85 void BookmarksFunction::Run() { 86 void BookmarksFunction::Run() {
86 BookmarkModel* model = profile()->GetBookmarkModel(); 87 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile());
87 if (!model->IsLoaded()) { 88 if (!model->IsLoaded()) {
88 // Bookmarks are not ready yet. We'll wait. 89 // Bookmarks are not ready yet. We'll wait.
89 registrar_.Add( 90 registrar_.Add(
90 this, chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED, 91 this, chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED,
91 content::NotificationService::AllBrowserContextsAndSources()); 92 content::NotificationService::AllBrowserContextsAndSources());
92 AddRef(); // Balanced in Observe(). 93 AddRef(); // Balanced in Observe().
93 return; 94 return;
94 } 95 }
95 96
96 bool success = RunImpl(); 97 bool success = RunImpl();
(...skipping 23 matching lines...) Expand all
120 } 121 }
121 122
122 void BookmarksFunction::Observe(int type, 123 void BookmarksFunction::Observe(int type,
123 const content::NotificationSource& source, 124 const content::NotificationSource& source,
124 const content::NotificationDetails& details) { 125 const content::NotificationDetails& details) {
125 DCHECK(type == chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED); 126 DCHECK(type == chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED);
126 Profile* source_profile = content::Source<Profile>(source).ptr(); 127 Profile* source_profile = content::Source<Profile>(source).ptr();
127 if (!source_profile || !source_profile->IsSameProfile(profile())) 128 if (!source_profile || !source_profile->IsSameProfile(profile()))
128 return; 129 return;
129 130
130 DCHECK(profile()->GetBookmarkModel()->IsLoaded()); 131 DCHECK(BookmarkModelFactory::GetForProfile(profile())->IsLoaded());
131 Run(); 132 Run();
132 Release(); // Balanced in Run(). 133 Release(); // Balanced in Run().
133 } 134 }
134 135
135 BookmarkExtensionEventRouter::BookmarkExtensionEventRouter( 136 BookmarkExtensionEventRouter::BookmarkExtensionEventRouter(
136 BookmarkModel* model) : model_(model) { 137 BookmarkModel* model) : model_(model) {
137 } 138 }
138 139
139 BookmarkExtensionEventRouter::~BookmarkExtensionEventRouter() { 140 BookmarkExtensionEventRouter::~BookmarkExtensionEventRouter() {
140 if (model_) { 141 if (model_) {
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 int64 id; 457 int64 id;
457 if (!base::StringToInt64(params->id, &id)) { 458 if (!base::StringToInt64(params->id, &id)) {
458 error_ = keys::kInvalidIdError; 459 error_ = keys::kInvalidIdError;
459 return false; 460 return false;
460 } 461 }
461 462
462 bool recursive = false; 463 bool recursive = false;
463 if (name() == RemoveTreeBookmarkFunction::function_name()) 464 if (name() == RemoveTreeBookmarkFunction::function_name())
464 recursive = true; 465 recursive = true;
465 466
466 BookmarkModel* model = profile()->GetBookmarkModel(); 467 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile());
467 if (!bookmark_extension_helpers::RemoveNode(model, id, recursive, &error_)) 468 if (!bookmark_extension_helpers::RemoveNode(model, id, recursive, &error_))
468 return false; 469 return false;
469 470
470 return true; 471 return true;
471 } 472 }
472 473
473 bool CreateBookmarkFunction::RunImpl() { 474 bool CreateBookmarkFunction::RunImpl() {
474 if (!EditBookmarksEnabled()) 475 if (!EditBookmarksEnabled())
475 return false; 476 return false;
476 477
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 scoped_ptr<bookmarks::Move::Params> params( 557 scoped_ptr<bookmarks::Move::Params> params(
557 bookmarks::Move::Params::Create(*args_)); 558 bookmarks::Move::Params::Create(*args_));
558 EXTENSION_FUNCTION_VALIDATE(params.get()); 559 EXTENSION_FUNCTION_VALIDATE(params.get());
559 560
560 int64 id; 561 int64 id;
561 if (!base::StringToInt64(params->id, &id)) { 562 if (!base::StringToInt64(params->id, &id)) {
562 error_ = keys::kInvalidIdError; 563 error_ = keys::kInvalidIdError;
563 return false; 564 return false;
564 } 565 }
565 566
566 BookmarkModel* model = profile()->GetBookmarkModel(); 567 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile());
567 const BookmarkNode* node = model->GetNodeByID(id); 568 const BookmarkNode* node = model->GetNodeByID(id);
568 if (!node) { 569 if (!node) {
569 error_ = keys::kNoNodeError; 570 error_ = keys::kNoNodeError;
570 return false; 571 return false;
571 } 572 }
572 if (model->is_permanent_node(node)) { 573 if (model->is_permanent_node(node)) {
573 error_ = keys::kModifySpecialError; 574 error_ = keys::kModifySpecialError;
574 return false; 575 return false;
575 } 576 }
576 577
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 virtual void GetBucketsForArgs(const ListValue* args, BucketList* buckets) { 706 virtual void GetBucketsForArgs(const ListValue* args, BucketList* buckets) {
706 DictionaryValue* json; 707 DictionaryValue* json;
707 if (!args->GetDictionary(0, &json)) 708 if (!args->GetDictionary(0, &json))
708 return; 709 return;
709 710
710 std::string parent_id; 711 std::string parent_id;
711 if (json->HasKey(keys::kParentIdKey)) { 712 if (json->HasKey(keys::kParentIdKey)) {
712 if (!json->GetString(keys::kParentIdKey, &parent_id)) 713 if (!json->GetString(keys::kParentIdKey, &parent_id))
713 return; 714 return;
714 } 715 }
715 BookmarkModel* model = profile_->GetBookmarkModel(); 716 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile_);
716 717
717 int64 parent_id_int64; 718 int64 parent_id_int64;
718 base::StringToInt64(parent_id, &parent_id_int64); 719 base::StringToInt64(parent_id, &parent_id_int64);
719 const BookmarkNode* parent = model->GetNodeByID(parent_id_int64); 720 const BookmarkNode* parent = model->GetNodeByID(parent_id_int64);
720 if (!parent) 721 if (!parent)
721 return; 722 return;
722 723
723 std::string bucket_id = UTF16ToUTF8(parent->GetTitle()); 724 std::string bucket_id = UTF16ToUTF8(parent->GetTitle());
724 std::string title; 725 std::string title;
725 json->GetString(keys::kTitleKey, &title); 726 json->GetString(keys::kTitleKey, &title);
(...skipping 17 matching lines...) Expand all
743 virtual void GetBucketsForArgs(const ListValue* args, BucketList* buckets) { 744 virtual void GetBucketsForArgs(const ListValue* args, BucketList* buckets) {
744 typedef std::list<int64> IdList; 745 typedef std::list<int64> IdList;
745 IdList ids; 746 IdList ids;
746 bool invalid_id = false; 747 bool invalid_id = false;
747 if (!RemoveBookmarkFunction::ExtractIds(args, &ids, &invalid_id) || 748 if (!RemoveBookmarkFunction::ExtractIds(args, &ids, &invalid_id) ||
748 invalid_id) { 749 invalid_id) {
749 return; 750 return;
750 } 751 }
751 752
752 for (IdList::iterator it = ids.begin(); it != ids.end(); ++it) { 753 for (IdList::iterator it = ids.begin(); it != ids.end(); ++it) {
753 BookmarkModel* model = profile_->GetBookmarkModel(); 754 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile_);
754 const BookmarkNode* node = model->GetNodeByID(*it); 755 const BookmarkNode* node = model->GetNodeByID(*it);
755 if (!node || node->is_root()) 756 if (!node || node->is_root())
756 return; 757 return;
757 758
758 std::string bucket_id; 759 std::string bucket_id;
759 bucket_id += UTF16ToUTF8(node->parent()->GetTitle()); 760 bucket_id += UTF16ToUTF8(node->parent()->GetTitle());
760 bucket_id += UTF16ToUTF8(node->GetTitle()); 761 bucket_id += UTF16ToUTF8(node->GetTitle());
761 bucket_id += node->url().spec(); 762 bucket_id += node->url().spec();
762 buckets->push_back(GetBucket(base::SHA1HashString(bucket_id))); 763 buckets->push_back(GetBucket(base::SHA1HashString(bucket_id)));
763 } 764 }
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 int index, 959 int index,
959 void* params) { 960 void* params) {
960 #if !defined(OS_ANDROID) 961 #if !defined(OS_ANDROID)
961 // Android does not have support for the standard exporter. 962 // Android does not have support for the standard exporter.
962 // TODO(jgreenwald): remove ifdef once extensions are no longer built on 963 // TODO(jgreenwald): remove ifdef once extensions are no longer built on
963 // Android. 964 // Android.
964 bookmark_html_writer::WriteBookmarks(profile(), path, NULL); 965 bookmark_html_writer::WriteBookmarks(profile(), path, NULL);
965 #endif 966 #endif
966 Release(); // Balanced in BookmarksIOFunction::SelectFile() 967 Release(); // Balanced in BookmarksIOFunction::SelectFile()
967 } 968 }
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/bookmark_expanded_state_tracker_unittest.cc ('k') | chrome/browser/bookmarks/bookmark_html_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698