| 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/ui/webui/downloads_dom_handler.h" | 5 #include "chrome/browser/ui/webui/downloads_dom_handler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 event, | 85 event, |
| 86 DOWNLOADS_DOM_EVENT_MAX); | 86 DOWNLOADS_DOM_EVENT_MAX); |
| 87 } | 87 } |
| 88 | 88 |
| 89 } // namespace | 89 } // namespace |
| 90 | 90 |
| 91 DownloadsDOMHandler::DownloadsDOMHandler(content::DownloadManager* dlm) | 91 DownloadsDOMHandler::DownloadsDOMHandler(content::DownloadManager* dlm) |
| 92 : search_text_(), | 92 : search_text_(), |
| 93 download_manager_(dlm), | 93 download_manager_(dlm), |
| 94 original_profile_download_manager_(NULL), | 94 original_profile_download_manager_(NULL), |
| 95 initialized_(false), |
| 95 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 96 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
| 96 // Create our fileicon data source. | 97 // Create our fileicon data source. |
| 97 Profile* profile = Profile::FromBrowserContext(dlm->GetBrowserContext()); | 98 Profile* profile = Profile::FromBrowserContext(dlm->GetBrowserContext()); |
| 98 ChromeURLDataManager::AddDataSource(profile, new FileIconSource()); | 99 ChromeURLDataManager::AddDataSource(profile, new FileIconSource()); |
| 99 | 100 |
| 100 // Figure out our parent DownloadManager, if any. | 101 // Figure out our parent DownloadManager, if any. |
| 101 Profile* original_profile = profile->GetOriginalProfile(); | 102 Profile* original_profile = profile->GetOriginalProfile(); |
| 102 if (original_profile != profile) { | 103 if (original_profile != profile) { |
| 103 original_profile_download_manager_ = DownloadServiceFactory::GetForProfile( | 104 original_profile_download_manager_ = DownloadServiceFactory::GetForProfile( |
| 104 original_profile)->GetDownloadManager(); | 105 original_profile)->GetDownloadManager(); |
| 105 } | 106 } |
| 106 } | 107 } |
| 107 | 108 |
| 108 DownloadsDOMHandler::~DownloadsDOMHandler() { | 109 DownloadsDOMHandler::~DownloadsDOMHandler() { |
| 109 ClearDownloadItems(); | 110 ClearDownloadItems(); |
| 110 download_manager_->RemoveObserver(this); | 111 download_manager_->RemoveObserver(this); |
| 111 if (original_profile_download_manager_) | 112 if (original_profile_download_manager_) |
| 112 original_profile_download_manager_->RemoveObserver(this); | 113 original_profile_download_manager_->RemoveObserver(this); |
| 113 } | 114 } |
| 114 | 115 |
| 115 // DownloadsDOMHandler, public: ----------------------------------------------- | 116 // DownloadsDOMHandler, public: ----------------------------------------------- |
| 116 | 117 |
| 117 void DownloadsDOMHandler::OnPageLoaded(const base::ListValue* args) { | 118 void DownloadsDOMHandler::OnPageLoaded(const base::ListValue* args) { |
| 119 if (initialized_) |
| 120 return; |
| 121 initialized_ = true; |
| 122 |
| 118 download_manager_->AddObserver(this); | 123 download_manager_->AddObserver(this); |
| 119 if (original_profile_download_manager_) | 124 if (original_profile_download_manager_) |
| 120 original_profile_download_manager_->AddObserver(this); | 125 original_profile_download_manager_->AddObserver(this); |
| 121 } | 126 } |
| 122 | 127 |
| 123 void DownloadsDOMHandler::RegisterMessages() { | 128 void DownloadsDOMHandler::RegisterMessages() { |
| 124 web_ui()->RegisterMessageCallback("onPageLoaded", | 129 web_ui()->RegisterMessageCallback("onPageLoaded", |
| 125 base::Bind(&DownloadsDOMHandler::OnPageLoaded, | 130 base::Bind(&DownloadsDOMHandler::OnPageLoaded, |
| 126 base::Unretained(this))); | 131 base::Unretained(this))); |
| 127 web_ui()->RegisterMessageCallback("getDownloads", | 132 web_ui()->RegisterMessageCallback("getDownloads", |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 } | 407 } |
| 403 | 408 |
| 404 content::DownloadItem* DownloadsDOMHandler::GetDownloadByValue( | 409 content::DownloadItem* DownloadsDOMHandler::GetDownloadByValue( |
| 405 const ListValue* args) { | 410 const ListValue* args) { |
| 406 int id; | 411 int id; |
| 407 if (ExtractIntegerValue(args, &id)) { | 412 if (ExtractIntegerValue(args, &id)) { |
| 408 return GetDownloadById(id); | 413 return GetDownloadById(id); |
| 409 } | 414 } |
| 410 return NULL; | 415 return NULL; |
| 411 } | 416 } |
| OLD | NEW |