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