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

Side by Side Diff: chrome/browser/android/provider/chrome_browser_provider.cc

Issue 386283002: Move bookmark_utils into bookmarks namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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/android/provider/chrome_browser_provider.h" 5 #include "chrome/browser/android/provider/chrome_browser_provider.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <list> 8 #include <list>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 int64* result) { 217 int64* result) {
218 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 218 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
219 DCHECK(result); 219 DCHECK(result);
220 GURL gurl = ParseAndMaybeAppendScheme(url, kDefaultUrlScheme); 220 GURL gurl = ParseAndMaybeAppendScheme(url, kDefaultUrlScheme);
221 221
222 // Check if the bookmark already exists. 222 // Check if the bookmark already exists.
223 const BookmarkNode* node = model->GetMostRecentlyAddedUserNodeForURL(gurl); 223 const BookmarkNode* node = model->GetMostRecentlyAddedUserNodeForURL(gurl);
224 if (!node) { 224 if (!node) {
225 const BookmarkNode* parent_node = NULL; 225 const BookmarkNode* parent_node = NULL;
226 if (parent_id >= 0) 226 if (parent_id >= 0)
227 parent_node = GetBookmarkNodeByID(model, parent_id); 227 parent_node = bookmarks::GetBookmarkNodeByID(model, parent_id);
228 if (!parent_node) 228 if (!parent_node)
229 parent_node = model->bookmark_bar_node(); 229 parent_node = model->bookmark_bar_node();
230 230
231 if (is_folder) 231 if (is_folder)
232 node = model->AddFolder(parent_node, parent_node->child_count(), title); 232 node = model->AddFolder(parent_node, parent_node->child_count(), title);
233 else 233 else
234 node = model->AddURL(parent_node, 0, title, gurl); 234 node = model->AddURL(parent_node, 0, title, gurl);
235 } 235 }
236 236
237 *result = node ? node ->id() : kInvalidBookmarkId; 237 *result = node ? node ->id() : kInvalidBookmarkId;
(...skipping 14 matching lines...) Expand all
252 252
253 int Run(const int64 id) { 253 int Run(const int64 id) {
254 id_to_delete_ = id; 254 id_to_delete_ = id;
255 RunOnUIThreadBlocking::Run( 255 RunOnUIThreadBlocking::Run(
256 base::Bind(&RemoveBookmarkTask::RunOnUIThread, model(), id)); 256 base::Bind(&RemoveBookmarkTask::RunOnUIThread, model(), id));
257 return deleted_; 257 return deleted_;
258 } 258 }
259 259
260 static void RunOnUIThread(BookmarkModel* model, const int64 id) { 260 static void RunOnUIThread(BookmarkModel* model, const int64 id) {
261 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 261 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
262 const BookmarkNode* node = GetBookmarkNodeByID(model, id); 262 const BookmarkNode* node = bookmarks::GetBookmarkNodeByID(model, id);
263 if (node && node->parent()) { 263 if (node && node->parent()) {
264 const BookmarkNode* parent_node = node->parent(); 264 const BookmarkNode* parent_node = node->parent();
265 model->Remove(parent_node, parent_node->GetIndexOf(node)); 265 model->Remove(parent_node, parent_node->GetIndexOf(node));
266 } 266 }
267 } 267 }
268 268
269 // Verify that the bookmark was actually removed. Called synchronously. 269 // Verify that the bookmark was actually removed. Called synchronously.
270 virtual void BookmarkNodeRemoved( 270 virtual void BookmarkNodeRemoved(
271 BookmarkModel* bookmark_model, 271 BookmarkModel* bookmark_model,
272 const BookmarkNode* parent, 272 const BookmarkNode* parent,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 model(), id, title, url, parent_id)); 325 model(), id, title, url, parent_id));
326 return updated_; 326 return updated_;
327 } 327 }
328 328
329 static void RunOnUIThread(BookmarkModel* model, 329 static void RunOnUIThread(BookmarkModel* model,
330 const int64 id, 330 const int64 id,
331 const base::string16& title, 331 const base::string16& title,
332 const base::string16& url, 332 const base::string16& url,
333 const int64 parent_id) { 333 const int64 parent_id) {
334 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 334 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
335 const BookmarkNode* node = GetBookmarkNodeByID(model, id); 335 const BookmarkNode* node = bookmarks::GetBookmarkNodeByID(model, id);
336 if (node) { 336 if (node) {
337 if (node->GetTitle() != title) 337 if (node->GetTitle() != title)
338 model->SetTitle(node, title); 338 model->SetTitle(node, title);
339 339
340 if (node->type() == BookmarkNode::URL) { 340 if (node->type() == BookmarkNode::URL) {
341 GURL bookmark_url = ParseAndMaybeAppendScheme(url, kDefaultUrlScheme); 341 GURL bookmark_url = ParseAndMaybeAppendScheme(url, kDefaultUrlScheme);
342 if (bookmark_url != node->url()) 342 if (bookmark_url != node->url())
343 model->SetURL(node, bookmark_url); 343 model->SetURL(node, bookmark_url);
344 } 344 }
345 345
346 if (parent_id >= 0 && 346 if (parent_id >= 0 &&
347 (!node->parent() || parent_id != node->parent()->id())) { 347 (!node->parent() || parent_id != node->parent()->id())) {
348 const BookmarkNode* new_parent = GetBookmarkNodeByID(model, parent_id); 348 const BookmarkNode* new_parent =
349 bookmarks::GetBookmarkNodeByID(model, parent_id);
349 350
350 if (new_parent) 351 if (new_parent)
351 model->Move(node, new_parent, 0); 352 model->Move(node, new_parent, 0);
352 } 353 }
353 } 354 }
354 } 355 }
355 356
356 // Verify that the bookmark was actually updated. Called synchronously. 357 // Verify that the bookmark was actually updated. Called synchronously.
357 virtual void BookmarkNodeChanged(BookmarkModel* bookmark_model, 358 virtual void BookmarkNodeChanged(BookmarkModel* bookmark_model,
358 const BookmarkNode* node) OVERRIDE { 359 const BookmarkNode* node) OVERRIDE {
(...skipping 21 matching lines...) Expand all
380 base::Bind(&BookmarkNodeExistsTask::RunOnUIThread, 381 base::Bind(&BookmarkNodeExistsTask::RunOnUIThread,
381 model(), id, &result)); 382 model(), id, &result));
382 return result; 383 return result;
383 } 384 }
384 385
385 static void RunOnUIThread(BookmarkModel* model, 386 static void RunOnUIThread(BookmarkModel* model,
386 const int64 id, 387 const int64 id,
387 bool* result) { 388 bool* result) {
388 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 389 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
389 DCHECK(result); 390 DCHECK(result);
390 *result = GetBookmarkNodeByID(model, id) != NULL; 391 *result = bookmarks::GetBookmarkNodeByID(model, id) != NULL;
391 } 392 }
392 393
393 private: 394 private:
394 DISALLOW_COPY_AND_ASSIGN(BookmarkNodeExistsTask); 395 DISALLOW_COPY_AND_ASSIGN(BookmarkNodeExistsTask);
395 }; 396 };
396 397
397 // Checks if a node belongs to the Mobile Bookmarks hierarchy branch. 398 // Checks if a node belongs to the Mobile Bookmarks hierarchy branch.
398 class IsInMobileBookmarksBranchTask : public BookmarkModelTask { 399 class IsInMobileBookmarksBranchTask : public BookmarkModelTask {
399 public: 400 public:
400 explicit IsInMobileBookmarksBranchTask(BookmarkModel* model) 401 explicit IsInMobileBookmarksBranchTask(BookmarkModel* model)
401 : BookmarkModelTask(model) {} 402 : BookmarkModelTask(model) {}
402 403
403 bool Run(const int64 id) { 404 bool Run(const int64 id) {
404 bool result = false; 405 bool result = false;
405 RunOnUIThreadBlocking::Run( 406 RunOnUIThreadBlocking::Run(
406 base::Bind(&IsInMobileBookmarksBranchTask::RunOnUIThread, 407 base::Bind(&IsInMobileBookmarksBranchTask::RunOnUIThread,
407 model(), id, &result)); 408 model(), id, &result));
408 return result; 409 return result;
409 } 410 }
410 411
411 static void RunOnUIThread(BookmarkModel* model, 412 static void RunOnUIThread(BookmarkModel* model,
412 const int64 id, 413 const int64 id,
413 bool *result) { 414 bool *result) {
414 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 415 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
415 DCHECK(result); 416 DCHECK(result);
416 const BookmarkNode* node = GetBookmarkNodeByID(model, id); 417 const BookmarkNode* node = bookmarks::GetBookmarkNodeByID(model, id);
417 const BookmarkNode* mobile_node = model->mobile_node(); 418 const BookmarkNode* mobile_node = model->mobile_node();
418 while (node && node != mobile_node) 419 while (node && node != mobile_node)
419 node = node->parent(); 420 node = node->parent();
420 421
421 *result = node == mobile_node; 422 *result = node == mobile_node;
422 } 423 }
423 424
424 private: 425 private:
425 DISALLOW_COPY_AND_ASSIGN(IsInMobileBookmarksBranchTask); 426 DISALLOW_COPY_AND_ASSIGN(IsInMobileBookmarksBranchTask);
426 }; 427 };
(...skipping 15 matching lines...) Expand all
442 } 443 }
443 444
444 static void RunOnUIThread(BookmarkModel* model, 445 static void RunOnUIThread(BookmarkModel* model,
445 const base::string16& title, 446 const base::string16& title,
446 const int64 parent_id, 447 const int64 parent_id,
447 int64* result) { 448 int64* result) {
448 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 449 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
449 DCHECK(result); 450 DCHECK(result);
450 451
451 // Invalid ids are assumed to refer to the Mobile Bookmarks folder. 452 // Invalid ids are assumed to refer to the Mobile Bookmarks folder.
452 const BookmarkNode* parent = parent_id >= 0 ? 453 const BookmarkNode* parent =
453 GetBookmarkNodeByID(model, parent_id) : model->mobile_node(); 454 parent_id >= 0 ? bookmarks::GetBookmarkNodeByID(model, parent_id)
455 : model->mobile_node();
454 DCHECK(parent); 456 DCHECK(parent);
455 457
456 bool in_mobile_bookmarks; 458 bool in_mobile_bookmarks;
457 IsInMobileBookmarksBranchTask::RunOnUIThread(model, parent->id(), 459 IsInMobileBookmarksBranchTask::RunOnUIThread(model, parent->id(),
458 &in_mobile_bookmarks); 460 &in_mobile_bookmarks);
459 if (!in_mobile_bookmarks) { 461 if (!in_mobile_bookmarks) {
460 // The parent folder must be inside the Mobile Bookmarks folder. 462 // The parent folder must be inside the Mobile Bookmarks folder.
461 *result = kInvalidBookmarkId; 463 *result = kInvalidBookmarkId;
462 return; 464 return;
463 } 465 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 base::Bind(&GetBookmarkNodeTask::RunOnUIThread, 554 base::Bind(&GetBookmarkNodeTask::RunOnUIThread,
553 model(), id, get_parent, get_children, jnode)); 555 model(), id, get_parent, get_children, jnode));
554 } 556 }
555 557
556 static void RunOnUIThread(BookmarkModel* model, 558 static void RunOnUIThread(BookmarkModel* model,
557 const int64 id, 559 const int64 id,
558 bool get_parent, 560 bool get_parent,
559 bool get_children, 561 bool get_children,
560 ScopedJavaGlobalRef<jobject>* jnode) { 562 ScopedJavaGlobalRef<jobject>* jnode) {
561 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 563 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
562 const BookmarkNode* node = GetBookmarkNodeByID(model, id); 564 const BookmarkNode* node = bookmarks::GetBookmarkNodeByID(model, id);
563 if (!node || !jnode) 565 if (!node || !jnode)
564 return; 566 return;
565 567
566 ScopedJavaGlobalRef<jobject> jparent; 568 ScopedJavaGlobalRef<jobject> jparent;
567 if (get_parent) { 569 if (get_parent) {
568 ConvertBookmarkNode(node->parent(), ScopedJavaLocalRef<jobject>(), 570 ConvertBookmarkNode(node->parent(), ScopedJavaLocalRef<jobject>(),
569 &jparent); 571 &jparent);
570 } 572 }
571 573
572 ConvertBookmarkNode(node, jparent, jnode); 574 ConvertBookmarkNode(node, jparent, jnode);
(...skipping 1057 matching lines...) Expand 10 before | Expand all | Expand 10 after
1630 Java_ChromeBrowserProvider_onBookmarkChanged(env, obj.obj()); 1632 Java_ChromeBrowserProvider_onBookmarkChanged(env, obj.obj());
1631 } else if (type == 1633 } else if (type ==
1632 chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED) { 1634 chrome::NOTIFICATION_HISTORY_KEYWORD_SEARCH_TERM_UPDATED) {
1633 JNIEnv* env = AttachCurrentThread(); 1635 JNIEnv* env = AttachCurrentThread();
1634 ScopedJavaLocalRef<jobject> obj = weak_java_provider_.get(env); 1636 ScopedJavaLocalRef<jobject> obj = weak_java_provider_.get(env);
1635 if (obj.is_null()) 1637 if (obj.is_null())
1636 return; 1638 return;
1637 Java_ChromeBrowserProvider_onSearchTermChanged(env, obj.obj()); 1639 Java_ChromeBrowserProvider_onSearchTermChanged(env, obj.obj());
1638 } 1640 }
1639 } 1641 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698