| OLD | NEW |
| 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_storage.h" | 5 #include "chrome/browser/bookmarks/bookmark_storage.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 } | 49 } |
| 50 | 50 |
| 51 void LoadCallback(const base::FilePath& path, | 51 void LoadCallback(const base::FilePath& path, |
| 52 BookmarkStorage* storage, | 52 BookmarkStorage* storage, |
| 53 BookmarkLoadDetails* details) { | 53 BookmarkLoadDetails* details) { |
| 54 startup_metric_utils::ScopedSlowStartupUMA | 54 startup_metric_utils::ScopedSlowStartupUMA |
| 55 scoped_timer("Startup.SlowStartupBookmarksLoad"); | 55 scoped_timer("Startup.SlowStartupBookmarksLoad"); |
| 56 bool bookmark_file_exists = base::PathExists(path); | 56 bool bookmark_file_exists = base::PathExists(path); |
| 57 if (bookmark_file_exists) { | 57 if (bookmark_file_exists) { |
| 58 JSONFileValueSerializer serializer(path); | 58 JSONFileValueSerializer serializer(path); |
| 59 scoped_ptr<Value> root(serializer.Deserialize(NULL, NULL)); | 59 scoped_ptr<base::Value> root(serializer.Deserialize(NULL, NULL)); |
| 60 | 60 |
| 61 if (root.get()) { | 61 if (root.get()) { |
| 62 // Building the index can take a while, so we do it on the background | 62 // Building the index can take a while, so we do it on the background |
| 63 // thread. | 63 // thread. |
| 64 int64 max_node_id = 0; | 64 int64 max_node_id = 0; |
| 65 BookmarkCodec codec; | 65 BookmarkCodec codec; |
| 66 TimeTicks start_time = TimeTicks::Now(); | 66 TimeTicks start_time = TimeTicks::Now(); |
| 67 codec.Decode(details->bb_node(), details->other_folder_node(), | 67 codec.Decode(details->bb_node(), details->other_folder_node(), |
| 68 details->mobile_folder_node(), &max_node_id, *root.get()); | 68 details->mobile_folder_node(), &max_node_id, *root.get()); |
| 69 details->set_max_id(std::max(max_node_id, details->max_id())); | 69 details->set_max_id(std::max(max_node_id, details->max_id())); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 void BookmarkStorage::BookmarkModelDeleted() { | 150 void BookmarkStorage::BookmarkModelDeleted() { |
| 151 // We need to save now as otherwise by the time SaveNow is invoked | 151 // We need to save now as otherwise by the time SaveNow is invoked |
| 152 // the model is gone. | 152 // the model is gone. |
| 153 if (writer_.HasPendingWrite()) | 153 if (writer_.HasPendingWrite()) |
| 154 SaveNow(); | 154 SaveNow(); |
| 155 model_ = NULL; | 155 model_ = NULL; |
| 156 } | 156 } |
| 157 | 157 |
| 158 bool BookmarkStorage::SerializeData(std::string* output) { | 158 bool BookmarkStorage::SerializeData(std::string* output) { |
| 159 BookmarkCodec codec; | 159 BookmarkCodec codec; |
| 160 scoped_ptr<Value> value(codec.Encode(model_)); | 160 scoped_ptr<base::Value> value(codec.Encode(model_)); |
| 161 JSONStringValueSerializer serializer(output); | 161 JSONStringValueSerializer serializer(output); |
| 162 serializer.set_pretty_print(true); | 162 serializer.set_pretty_print(true); |
| 163 return serializer.Serialize(*(value.get())); | 163 return serializer.Serialize(*(value.get())); |
| 164 } | 164 } |
| 165 | 165 |
| 166 void BookmarkStorage::OnLoadFinished() { | 166 void BookmarkStorage::OnLoadFinished() { |
| 167 if (!model_) | 167 if (!model_) |
| 168 return; | 168 return; |
| 169 | 169 |
| 170 model_->DoneLoading(details_.release()); | 170 model_->DoneLoading(details_.release()); |
| 171 } | 171 } |
| 172 | 172 |
| 173 bool BookmarkStorage::SaveNow() { | 173 bool BookmarkStorage::SaveNow() { |
| 174 if (!model_ || !model_->loaded()) { | 174 if (!model_ || !model_->loaded()) { |
| 175 // We should only get here if we have a valid model and it's finished | 175 // We should only get here if we have a valid model and it's finished |
| 176 // loading. | 176 // loading. |
| 177 NOTREACHED(); | 177 NOTREACHED(); |
| 178 return false; | 178 return false; |
| 179 } | 179 } |
| 180 | 180 |
| 181 std::string data; | 181 std::string data; |
| 182 if (!SerializeData(&data)) | 182 if (!SerializeData(&data)) |
| 183 return false; | 183 return false; |
| 184 writer_.WriteNow(data); | 184 writer_.WriteNow(data); |
| 185 return true; | 185 return true; |
| 186 } | 186 } |
| OLD | NEW |