| OLD | NEW | 
|    1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |    1 // Copyright (c) 2011 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/extensions/extension_bookmarks_module.h" |    5 #include "chrome/browser/extensions/extension_bookmarks_module.h" | 
|    6  |    6  | 
|    7 #include "base/file_path.h" |    7 #include "base/file_path.h" | 
|    8 #include "base/i18n/file_util_icu.h" |    8 #include "base/i18n/file_util_icu.h" | 
|    9 #include "base/i18n/time_formatting.h" |    9 #include "base/i18n/time_formatting.h" | 
|   10 #include "base/json/json_writer.h" |   10 #include "base/json/json_writer.h" | 
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  111  |  111  | 
|  112 void BookmarksFunction::Observe(NotificationType type, |  112 void BookmarksFunction::Observe(NotificationType type, | 
|  113                                 const NotificationSource& source, |  113                                 const NotificationSource& source, | 
|  114                                 const NotificationDetails& details) { |  114                                 const NotificationDetails& details) { | 
|  115   DCHECK(type == NotificationType::BOOKMARK_MODEL_LOADED); |  115   DCHECK(type == NotificationType::BOOKMARK_MODEL_LOADED); | 
|  116   DCHECK(profile()->GetBookmarkModel()->IsLoaded()); |  116   DCHECK(profile()->GetBookmarkModel()->IsLoaded()); | 
|  117   Run(); |  117   Run(); | 
|  118   Release();  // Balanced in Run(). |  118   Release();  // Balanced in Run(). | 
|  119 } |  119 } | 
|  120  |  120  | 
|  121 // static |  121 ExtensionBookmarkEventRouter::ExtensionBookmarkEventRouter( | 
|  122 ExtensionBookmarkEventRouter* ExtensionBookmarkEventRouter::GetInstance() { |  122     BookmarkModel* model) : model_(model) { | 
|  123   return Singleton<ExtensionBookmarkEventRouter>::get(); |  | 
|  124 } |  | 
|  125  |  | 
|  126 ExtensionBookmarkEventRouter::ExtensionBookmarkEventRouter() { |  | 
|  127 } |  123 } | 
|  128  |  124  | 
|  129 ExtensionBookmarkEventRouter::~ExtensionBookmarkEventRouter() { |  125 ExtensionBookmarkEventRouter::~ExtensionBookmarkEventRouter() { | 
|  130 } |  126   if (model_) { | 
|  131  |  127     model_->RemoveObserver(this); | 
|  132 void ExtensionBookmarkEventRouter::Observe(BookmarkModel* model) { |  | 
|  133   if (models_.find(model) == models_.end()) { |  | 
|  134     model->AddObserver(this); |  | 
|  135     models_.insert(model); |  | 
|  136   } |  128   } | 
|  137 } |  129 } | 
|  138  |  130  | 
 |  131 void ExtensionBookmarkEventRouter::Init() { | 
 |  132   model_->AddObserver(this); | 
 |  133 } | 
 |  134  | 
|  139 void ExtensionBookmarkEventRouter::DispatchEvent(Profile *profile, |  135 void ExtensionBookmarkEventRouter::DispatchEvent(Profile *profile, | 
|  140                                                  const char* event_name, |  136                                                  const char* event_name, | 
|  141                                                  const std::string& json_args) { |  137                                                  const std::string& json_args) { | 
|  142   if (profile->GetExtensionEventRouter()) { |  138   if (profile->GetExtensionEventRouter()) { | 
|  143     profile->GetExtensionEventRouter()->DispatchEventToRenderers( |  139     profile->GetExtensionEventRouter()->DispatchEventToRenderers( | 
|  144         event_name, json_args, NULL, GURL()); |  140         event_name, json_args, NULL, GURL()); | 
|  145   } |  141   } | 
|  146 } |  142 } | 
|  147  |  143  | 
|  148 void ExtensionBookmarkEventRouter::Loaded(BookmarkModel* model) { |  144 void ExtensionBookmarkEventRouter::Loaded(BookmarkModel* model) { | 
|  149   // TODO(erikkay): Perhaps we should send this event down to the extension |  145   // TODO(erikkay): Perhaps we should send this event down to the extension | 
|  150   // so they know when it's safe to use the API? |  146   // so they know when it's safe to use the API? | 
|  151 } |  147 } | 
|  152  |  148  | 
 |  149 void ExtensionBookmarkEventRouter::BookmarkModelBeingDeleted( | 
 |  150     BookmarkModel* model) { | 
 |  151   model_ = NULL; | 
 |  152 } | 
 |  153  | 
|  153 void ExtensionBookmarkEventRouter::BookmarkNodeMoved( |  154 void ExtensionBookmarkEventRouter::BookmarkNodeMoved( | 
|  154     BookmarkModel* model, |  155     BookmarkModel* model, | 
|  155     const BookmarkNode* old_parent, |  156     const BookmarkNode* old_parent, | 
|  156     int old_index, |  157     int old_index, | 
|  157     const BookmarkNode* new_parent, |  158     const BookmarkNode* new_parent, | 
|  158     int new_index) { |  159     int new_index) { | 
|  159   ListValue args; |  160   ListValue args; | 
|  160   const BookmarkNode* node = new_parent->GetChild(new_index); |  161   const BookmarkNode* node = new_parent->GetChild(new_index); | 
|  161   args.Append(new StringValue(base::Int64ToString(node->id()))); |  162   args.Append(new StringValue(base::Int64ToString(node->id()))); | 
|  162   DictionaryValue* object_args = new DictionaryValue(); |  163   DictionaryValue* object_args = new DictionaryValue(); | 
| (...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  925   SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE); |  926   SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE); | 
|  926   return true; |  927   return true; | 
|  927 } |  928 } | 
|  928  |  929  | 
|  929 void ExportBookmarksFunction::FileSelected(const FilePath& path, |  930 void ExportBookmarksFunction::FileSelected(const FilePath& path, | 
|  930                                            int index, |  931                                            int index, | 
|  931                                            void* params) { |  932                                            void* params) { | 
|  932   bookmark_html_writer::WriteBookmarks(profile(), path, NULL); |  933   bookmark_html_writer::WriteBookmarks(profile(), path, NULL); | 
|  933   Release();  // Balanced in BookmarksIOFunction::SelectFile() |  934   Release();  // Balanced in BookmarksIOFunction::SelectFile() | 
|  934 } |  935 } | 
| OLD | NEW |