| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_storage.h" | 5 #include "chrome/browser/bookmarks/bookmark_storage.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/histogram.h" | 9 #include "base/histogram.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 details_(details) { | 74 details_(details) { |
| 75 } | 75 } |
| 76 | 76 |
| 77 virtual void Run() { | 77 virtual void Run() { |
| 78 bool bookmark_file_exists = file_util::PathExists(path_); | 78 bool bookmark_file_exists = file_util::PathExists(path_); |
| 79 if (bookmark_file_exists) { | 79 if (bookmark_file_exists) { |
| 80 JSONFileValueSerializer serializer(path_); | 80 JSONFileValueSerializer serializer(path_); |
| 81 scoped_ptr<Value> root(serializer.Deserialize(NULL)); | 81 scoped_ptr<Value> root(serializer.Deserialize(NULL)); |
| 82 | 82 |
| 83 if (root.get()) { | 83 if (root.get()) { |
| 84 // Building the index cane take a while, so we do it on the background | 84 // Building the index can take a while, so we do it on the background |
| 85 // thread. | 85 // thread. |
| 86 int64 max_node_id = 0; | 86 int64 max_node_id = 0; |
| 87 BookmarkCodec codec; | 87 BookmarkCodec codec; |
| 88 TimeTicks start_time = TimeTicks::Now(); | 88 TimeTicks start_time = TimeTicks::Now(); |
| 89 codec.Decode(details_->bb_node(), details_->other_folder_node(), | 89 codec.Decode(details_->bb_node(), details_->other_folder_node(), |
| 90 &max_node_id, *root.get()); | 90 &max_node_id, *root.get()); |
| 91 details_->set_max_id(std::max(max_node_id, details_->max_id())); | 91 details_->set_max_id(std::max(max_node_id, details_->max_id())); |
| 92 details_->set_computed_checksum(codec.computed_checksum()); | 92 details_->set_computed_checksum(codec.computed_checksum()); |
| 93 details_->set_stored_checksum(codec.stored_checksum()); | 93 details_->set_stored_checksum(codec.stored_checksum()); |
| 94 details_->set_ids_reassigned(codec.ids_reassigned()); | 94 details_->set_ids_reassigned(codec.ids_reassigned()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 109 bookmark_file_exists, path_)); | 109 bookmark_file_exists, path_)); |
| 110 } else { | 110 } else { |
| 111 storage_->OnLoadFinished(bookmark_file_exists, path_); | 111 storage_->OnLoadFinished(bookmark_file_exists, path_); |
| 112 } | 112 } |
| 113 } | 113 } |
| 114 | 114 |
| 115 private: | 115 private: |
| 116 // Adds node to the model's index, recursing through all children as well. | 116 // Adds node to the model's index, recursing through all children as well. |
| 117 void AddBookmarksToIndex(BookmarkNode* node) { | 117 void AddBookmarksToIndex(BookmarkNode* node) { |
| 118 if (node->is_url()) { | 118 if (node->is_url()) { |
| 119 details_->index()->Add(node); | 119 if (node->GetURL().is_valid()) |
| 120 details_->index()->Add(node); |
| 120 } else { | 121 } else { |
| 121 for (int i = 0; i < node->GetChildCount(); ++i) | 122 for (int i = 0; i < node->GetChildCount(); ++i) |
| 122 AddBookmarksToIndex(node->GetChild(i)); | 123 AddBookmarksToIndex(node->GetChild(i)); |
| 123 } | 124 } |
| 124 } | 125 } |
| 125 | 126 |
| 126 const FilePath path_; | 127 const FilePath path_; |
| 127 MessageLoop* loop_; | 128 MessageLoop* loop_; |
| 128 scoped_refptr<BookmarkStorage> storage_; | 129 scoped_refptr<BookmarkStorage> storage_; |
| 129 LoadDetails* details_; | 130 LoadDetails* details_; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 } | 272 } |
| 272 | 273 |
| 273 void BookmarkStorage::RunTaskOnBackendThread(Task* task) const { | 274 void BookmarkStorage::RunTaskOnBackendThread(Task* task) const { |
| 274 if (backend_thread()) { | 275 if (backend_thread()) { |
| 275 backend_thread()->message_loop()->PostTask(FROM_HERE, task); | 276 backend_thread()->message_loop()->PostTask(FROM_HERE, task); |
| 276 } else { | 277 } else { |
| 277 task->Run(); | 278 task->Run(); |
| 278 delete task; | 279 delete task; |
| 279 } | 280 } |
| 280 } | 281 } |
| OLD | NEW |