| 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::FromBrowserContext(dlm->GetBrowserContext())-> | 98 Profile::FromBrowserContext(dlm->GetBrowserContext())-> |
| 98 GetChromeURLDataManager()->AddDataSource(new FileIconSource()); | 99 GetChromeURLDataManager()->AddDataSource(new FileIconSource()); |
| 99 | 100 |
| 100 // Figure out our parent DownloadManager, if any. | 101 // Figure out our parent DownloadManager, if any. |
| 101 Profile* profile = | 102 Profile* profile = |
| 102 Profile::FromBrowserContext(download_manager_->GetBrowserContext()); | 103 Profile::FromBrowserContext(download_manager_->GetBrowserContext()); |
| 103 Profile* original_profile = profile->GetOriginalProfile(); | 104 Profile* original_profile = profile->GetOriginalProfile(); |
| 104 if (original_profile != profile) { | 105 if (original_profile != profile) { |
| 105 original_profile_download_manager_ = DownloadServiceFactory::GetForProfile( | 106 original_profile_download_manager_ = DownloadServiceFactory::GetForProfile( |
| 106 original_profile)->GetDownloadManager(); | 107 original_profile)->GetDownloadManager(); |
| 107 } | 108 } |
| 108 } | 109 } |
| 109 | 110 |
| 110 DownloadsDOMHandler::~DownloadsDOMHandler() { | 111 DownloadsDOMHandler::~DownloadsDOMHandler() { |
| 111 ClearDownloadItems(); | 112 ClearDownloadItems(); |
| 112 download_manager_->RemoveObserver(this); | 113 download_manager_->RemoveObserver(this); |
| 113 if (original_profile_download_manager_) | 114 if (original_profile_download_manager_) |
| 114 original_profile_download_manager_->RemoveObserver(this); | 115 original_profile_download_manager_->RemoveObserver(this); |
| 115 } | 116 } |
| 116 | 117 |
| 117 // DownloadsDOMHandler, public: ----------------------------------------------- | 118 // DownloadsDOMHandler, public: ----------------------------------------------- |
| 118 | 119 |
| 119 void DownloadsDOMHandler::OnPageLoaded(const base::ListValue* args) { | 120 void DownloadsDOMHandler::OnPageLoaded(const base::ListValue* args) { |
| 121 if (initialized_) |
| 122 return; |
| 123 initialized_ = true; |
| 124 |
| 120 download_manager_->AddObserver(this); | 125 download_manager_->AddObserver(this); |
| 121 if (original_profile_download_manager_) | 126 if (original_profile_download_manager_) |
| 122 original_profile_download_manager_->AddObserver(this); | 127 original_profile_download_manager_->AddObserver(this); |
| 123 } | 128 } |
| 124 | 129 |
| 125 void DownloadsDOMHandler::RegisterMessages() { | 130 void DownloadsDOMHandler::RegisterMessages() { |
| 126 web_ui()->RegisterMessageCallback("onPageLoaded", | 131 web_ui()->RegisterMessageCallback("onPageLoaded", |
| 127 base::Bind(&DownloadsDOMHandler::OnPageLoaded, | 132 base::Bind(&DownloadsDOMHandler::OnPageLoaded, |
| 128 base::Unretained(this))); | 133 base::Unretained(this))); |
| 129 web_ui()->RegisterMessageCallback("getDownloads", | 134 web_ui()->RegisterMessageCallback("getDownloads", |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 } | 409 } |
| 405 | 410 |
| 406 content::DownloadItem* DownloadsDOMHandler::GetDownloadByValue( | 411 content::DownloadItem* DownloadsDOMHandler::GetDownloadByValue( |
| 407 const ListValue* args) { | 412 const ListValue* args) { |
| 408 int id; | 413 int id; |
| 409 if (ExtractIntegerValue(args, &id)) { | 414 if (ExtractIntegerValue(args, &id)) { |
| 410 return GetDownloadById(id); | 415 return GetDownloadById(id); |
| 411 } | 416 } |
| 412 return NULL; | 417 return NULL; |
| 413 } | 418 } |
| OLD | NEW |