Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: chrome/browser/extensions/api/downloads/downloads_api.cc

Issue 10805020: Kill DownloadItem::IsOtr() (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: . Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/extensions/api/downloads/downloads_api.h" 5 #include "chrome/browser/extensions/api/downloads/downloads_api.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cctype> 8 #include <cctype>
9 #include <iterator> 9 #include <iterator>
10 #include <set> 10 #include <set>
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 bool ValidateFilename(const string16& filename) { 179 bool ValidateFilename(const string16& filename) {
180 // TODO(benjhayden): More robust validation of filename. 180 // TODO(benjhayden): More robust validation of filename.
181 if ((filename.find('/') != string16::npos) || 181 if ((filename.find('/') != string16::npos) ||
182 (filename.find('\\') != string16::npos)) 182 (filename.find('\\') != string16::npos))
183 return false; 183 return false;
184 if (filename.size() >= 2u && filename[0] == L'.' && filename[1] == L'.') 184 if (filename.size() >= 2u && filename[0] == L'.' && filename[1] == L'.')
185 return false; 185 return false;
186 return true; 186 return true;
187 } 187 }
188 188
189 scoped_ptr<base::DictionaryValue> DownloadItemToJSON(DownloadItem* item) { 189 scoped_ptr<base::DictionaryValue> DownloadItemToJSON(
190 DownloadItem* item,
191 bool incognito) {
190 base::DictionaryValue* json = new base::DictionaryValue(); 192 base::DictionaryValue* json = new base::DictionaryValue();
191 json->SetInteger(kIdKey, item->GetId()); 193 json->SetInteger(kIdKey, item->GetId());
192 json->SetString(kUrlKey, item->GetOriginalUrl().spec()); 194 json->SetString(kUrlKey, item->GetOriginalUrl().spec());
193 json->SetString(kFilenameKey, item->GetFullPath().LossyDisplayName()); 195 json->SetString(kFilenameKey, item->GetFullPath().LossyDisplayName());
194 json->SetString(kDangerKey, DangerString(item->GetDangerType())); 196 json->SetString(kDangerKey, DangerString(item->GetDangerType()));
195 if (item->GetDangerType() != content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS) 197 if (item->GetDangerType() != content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS)
196 json->SetBoolean(kDangerAcceptedKey, 198 json->SetBoolean(kDangerAcceptedKey,
197 item->GetSafetyState() == DownloadItem::DANGEROUS_BUT_VALIDATED); 199 item->GetSafetyState() == DownloadItem::DANGEROUS_BUT_VALIDATED);
198 json->SetString(kStateKey, StateString(item->GetState())); 200 json->SetString(kStateKey, StateString(item->GetState()));
199 json->SetBoolean(kPausedKey, item->IsPaused()); 201 json->SetBoolean(kPausedKey, item->IsPaused());
200 json->SetString(kMimeKey, item->GetMimeType()); 202 json->SetString(kMimeKey, item->GetMimeType());
201 json->SetInteger(kStartTimeKey, 203 json->SetInteger(kStartTimeKey,
202 (item->GetStartTime() - base::Time::UnixEpoch()).InMilliseconds()); 204 (item->GetStartTime() - base::Time::UnixEpoch()).InMilliseconds());
203 json->SetInteger(kBytesReceivedKey, item->GetReceivedBytes()); 205 json->SetInteger(kBytesReceivedKey, item->GetReceivedBytes());
204 json->SetInteger(kTotalBytesKey, item->GetTotalBytes()); 206 json->SetInteger(kTotalBytesKey, item->GetTotalBytes());
205 json->SetBoolean(kIncognito, item->IsOtr()); 207 json->SetBoolean(kIncognito, incognito);
206 if (item->GetState() == DownloadItem::INTERRUPTED) { 208 if (item->GetState() == DownloadItem::INTERRUPTED) {
207 json->SetInteger(kErrorKey, static_cast<int>(item->GetLastReason())); 209 json->SetInteger(kErrorKey, static_cast<int>(item->GetLastReason()));
208 } else if (item->GetState() == DownloadItem::CANCELLED) { 210 } else if (item->GetState() == DownloadItem::CANCELLED) {
209 json->SetInteger(kErrorKey, static_cast<int>( 211 json->SetInteger(kErrorKey, static_cast<int>(
210 content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED)); 212 content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED));
211 } 213 }
212 // TODO(benjhayden): Implement endTime and fileSize. 214 // TODO(benjhayden): Implement endTime and fileSize.
213 // json->SetInteger(kEndTimeKey, -1); 215 // json->SetInteger(kEndTimeKey, -1);
214 json->SetInteger(kFileSizeKey, item->GetTotalBytes()); 216 json->SetInteger(kFileSizeKey, item->GetTotalBytes());
215 return scoped_ptr<base::DictionaryValue>(json); 217 return scoped_ptr<base::DictionaryValue>(json);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 sorter_types[kStartTimeKey] = DownloadQuery::SORT_START_TIME; 309 sorter_types[kStartTimeKey] = DownloadQuery::SORT_START_TIME;
308 sorter_types[kStateKey] = DownloadQuery::SORT_STATE; 310 sorter_types[kStateKey] = DownloadQuery::SORT_STATE;
309 sorter_types[kTotalBytesKey] = DownloadQuery::SORT_TOTAL_BYTES; 311 sorter_types[kTotalBytesKey] = DownloadQuery::SORT_TOTAL_BYTES;
310 sorter_types[kUrlKey] = DownloadQuery::SORT_URL; 312 sorter_types[kUrlKey] = DownloadQuery::SORT_URL;
311 } 313 }
312 314
313 bool IsNotTemporaryDownloadFilter(const DownloadItem& item) { 315 bool IsNotTemporaryDownloadFilter(const DownloadItem& item) {
314 return !item.IsTemporary(); 316 return !item.IsTemporary();
315 } 317 }
316 318
319 // Set |manager| to the on-record DownloadManager, and |incognito_manager| to
320 // the off-record DownloadManager if one exists and is requested via
321 // |include_incognito|. This should work regardless of whether |profile| is
322 // original or incognito.
317 void GetManagers( 323 void GetManagers(
318 Profile* profile, 324 Profile* profile,
319 bool include_incognito, 325 bool include_incognito,
320 DownloadManager** manager, DownloadManager** incognito_manager) { 326 DownloadManager** manager,
321 *manager = BrowserContext::GetDownloadManager(profile); 327 DownloadManager** incognito_manager) {
322 *incognito_manager = NULL; 328 *manager = BrowserContext::GetDownloadManager(profile->GetOriginalProfile());
323 if (include_incognito && profile->HasOffTheRecordProfile()) { 329 if (profile->HasOffTheRecordProfile() &&
330 (include_incognito ||
331 (profile != profile->GetOriginalProfile()))) {
324 *incognito_manager = BrowserContext::GetDownloadManager( 332 *incognito_manager = BrowserContext::GetDownloadManager(
325 profile->GetOffTheRecordProfile()); 333 profile->GetOffTheRecordProfile());
334 } else {
335 *incognito_manager = NULL;
326 } 336 }
327 } 337 }
328 338
329 DownloadItem* GetActiveItem(Profile* profile, bool include_incognito, int id) { 339 DownloadItem* GetActiveItem(Profile* profile, bool include_incognito, int id) {
330 DownloadManager* manager = NULL; 340 DownloadManager* manager = NULL;
331 DownloadManager* incognito_manager = NULL; 341 DownloadManager* incognito_manager = NULL;
332 GetManagers(profile, include_incognito, &manager, &incognito_manager); 342 GetManagers(profile, include_incognito, &manager, &incognito_manager);
333 DownloadItem* download_item = manager->GetDownload(id); 343 DownloadItem* download_item = manager->GetDownload(id);
334 if (!download_item && incognito_manager) 344 if (!download_item && incognito_manager)
335 download_item = incognito_manager->GetDownload(id); 345 download_item = incognito_manager->GetDownload(id);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 if (sorter_type == sorter_types.Get().end()) { 395 if (sorter_type == sorter_types.Get().end()) {
386 *error = download_extension_errors::kInvalidOrderByError; 396 *error = download_extension_errors::kInvalidOrderByError;
387 return; 397 return;
388 } 398 }
389 query->AddSorter(sorter_type->second, direction); 399 query->AddSorter(sorter_type->second, direction);
390 } 400 }
391 } 401 }
392 402
393 void RunDownloadQuery( 403 void RunDownloadQuery(
394 const extensions::api::downloads::DownloadQuery& query_in, 404 const extensions::api::downloads::DownloadQuery& query_in,
395 Profile* profile, 405 DownloadManager* manager,
396 bool include_incognito, 406 DownloadManager* incognito_manager,
397 std::string* error, 407 std::string* error,
398 DownloadQuery::DownloadVector* results) { 408 DownloadQuery::DownloadVector* results) {
399 // TODO(benjhayden): Consider switching from LazyInstance to explicit string 409 // TODO(benjhayden): Consider switching from LazyInstance to explicit string
400 // comparisons. 410 // comparisons.
401 static base::LazyInstance<FilterTypeMap> filter_types = 411 static base::LazyInstance<FilterTypeMap> filter_types =
402 LAZY_INSTANCE_INITIALIZER; 412 LAZY_INSTANCE_INITIALIZER;
403 if (filter_types.Get().size() == 0) 413 if (filter_types.Get().size() == 0)
404 InitFilterTypeMap(filter_types.Get()); 414 InitFilterTypeMap(filter_types.Get());
405 415
406 DownloadQuery query_out; 416 DownloadQuery query_out;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 FilterTypeMap::const_iterator filter_type = 452 FilterTypeMap::const_iterator filter_type =
443 filter_types.Get().find(query_json_field.key()); 453 filter_types.Get().find(query_json_field.key());
444 if (filter_type != filter_types.Get().end()) { 454 if (filter_type != filter_types.Get().end()) {
445 if (!query_out.AddFilter(filter_type->second, query_json_field.value())) { 455 if (!query_out.AddFilter(filter_type->second, query_json_field.value())) {
446 *error = download_extension_errors::kInvalidFilterError; 456 *error = download_extension_errors::kInvalidFilterError;
447 return; 457 return;
448 } 458 }
449 } 459 }
450 } 460 }
451 461
452 DownloadManager* manager = NULL;
453 DownloadManager* incognito_manager = NULL;
454 GetManagers(profile, include_incognito, &manager, &incognito_manager);
455 DownloadQuery::DownloadVector all_items; 462 DownloadQuery::DownloadVector all_items;
456 if (query_in.id.get()) { 463 if (query_in.id.get()) {
457 DownloadItem* item = manager->GetDownload(*query_in.id.get()); 464 DownloadItem* item = manager->GetDownload(*query_in.id.get());
458 if (!item && incognito_manager) 465 if (!item && incognito_manager)
459 item = incognito_manager->GetDownload(*query_in.id.get()); 466 item = incognito_manager->GetDownload(*query_in.id.get());
460 if (item) 467 if (item)
461 all_items.push_back(item); 468 all_items.push_back(item);
462 } else { 469 } else {
463 manager->GetAllDownloads(FilePath(FILE_PATH_LITERAL("")), &all_items); 470 manager->GetAllDownloads(FilePath(FILE_PATH_LITERAL("")), &all_items);
464 if (incognito_manager) 471 if (incognito_manager)
465 incognito_manager->GetAllDownloads( 472 incognito_manager->GetAllDownloads(
466 FilePath(FILE_PATH_LITERAL("")), &all_items); 473 FilePath(FILE_PATH_LITERAL("")), &all_items);
467 } 474 }
468 query_out.Search(all_items.begin(), all_items.end(), results); 475 query_out.Search(all_items.begin(), all_items.end(), results);
469 } 476 }
470 477
478 void DispatchEventInternal(
479 Profile* target_profile,
480 const char* event_name,
481 const std::string& json_args) {
482 target_profile->GetExtensionEventRouter()->DispatchEventToRenderers(
483 event_name,
484 json_args,
485 target_profile,
486 GURL(),
487 extensions::EventFilteringInfo());
488
489 ExtensionDownloadsEventRouter::DownloadsNotificationSource
490 notification_source;
491 notification_source.event_name = event_name;
492 notification_source.profile = target_profile;
493 content::Source<ExtensionDownloadsEventRouter::DownloadsNotificationSource>
494 content_source(&notification_source);
495 std::string args_copy(json_args);
496 content::NotificationService::current()->Notify(
497 chrome::NOTIFICATION_EXTENSION_DOWNLOADS_EVENT,
498 content_source,
499 content::Details<std::string>(&args_copy));
500 }
501
471 } // namespace 502 } // namespace
472 503
473 DownloadsDownloadFunction::DownloadsDownloadFunction() {} 504 DownloadsDownloadFunction::DownloadsDownloadFunction() {}
474 DownloadsDownloadFunction::~DownloadsDownloadFunction() {} 505 DownloadsDownloadFunction::~DownloadsDownloadFunction() {}
475 506
476 bool DownloadsDownloadFunction::RunImpl() { 507 bool DownloadsDownloadFunction::RunImpl() {
477 scoped_ptr<extensions::api::downloads::Download::Params> params( 508 scoped_ptr<extensions::api::downloads::Download::Params> params(
478 extensions::api::downloads::Download::Params::Create(*args_)); 509 extensions::api::downloads::Download::Params::Create(*args_));
479 EXTENSION_FUNCTION_VALIDATE(params.get()); 510 EXTENSION_FUNCTION_VALIDATE(params.get());
480 const extensions::api::downloads::DownloadOptions& options = params->options; 511 const extensions::api::downloads::DownloadOptions& options = params->options;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 SendResponse(error_.empty()); 594 SendResponse(error_.empty());
564 } 595 }
565 596
566 DownloadsSearchFunction::DownloadsSearchFunction() {} 597 DownloadsSearchFunction::DownloadsSearchFunction() {}
567 DownloadsSearchFunction::~DownloadsSearchFunction() {} 598 DownloadsSearchFunction::~DownloadsSearchFunction() {}
568 599
569 bool DownloadsSearchFunction::RunImpl() { 600 bool DownloadsSearchFunction::RunImpl() {
570 scoped_ptr<extensions::api::downloads::Search::Params> params( 601 scoped_ptr<extensions::api::downloads::Search::Params> params(
571 extensions::api::downloads::Search::Params::Create(*args_)); 602 extensions::api::downloads::Search::Params::Create(*args_));
572 EXTENSION_FUNCTION_VALIDATE(params.get()); 603 EXTENSION_FUNCTION_VALIDATE(params.get());
604 DownloadManager* manager = NULL;
605 DownloadManager* incognito_manager = NULL;
606 GetManagers(profile(), include_incognito(), &manager, &incognito_manager);
573 DownloadQuery::DownloadVector results; 607 DownloadQuery::DownloadVector results;
574 RunDownloadQuery(params->query, profile(), include_incognito(), 608 RunDownloadQuery(params->query,
575 &error_, &results); 609 manager,
610 incognito_manager,
611 &error_,
612 &results);
576 if (!error_.empty()) 613 if (!error_.empty())
577 return false; 614 return false;
615
578 base::ListValue* json_results = new base::ListValue(); 616 base::ListValue* json_results = new base::ListValue();
579 for (DownloadManager::DownloadVector::const_iterator it = results.begin(); 617 for (DownloadManager::DownloadVector::const_iterator it = results.begin();
580 it != results.end(); ++it) { 618 it != results.end(); ++it) {
581 scoped_ptr<base::DictionaryValue> item(DownloadItemToJSON(*it)); 619 DownloadItem* item = *it;
582 json_results->Append(item.release()); 620 int32 download_id = item->GetId();
621 bool off_record = ((incognito_manager != NULL) &&
622 (incognito_manager->GetDownload(download_id) != NULL));
623 scoped_ptr<base::DictionaryValue> json_item(DownloadItemToJSON(
624 *it, off_record));
625 json_results->Append(json_item.release());
Randy Smith (Not in Mondays) 2012/08/02 17:52:17 I wince a little bit at RunDownloadQuery having th
benjhayden 2012/08/13 15:08:09 The downloads are all mixed together, so that woul
583 } 626 }
584 SetResult(json_results); 627 SetResult(json_results);
585 RecordApiFunctions(DOWNLOADS_FUNCTION_SEARCH); 628 RecordApiFunctions(DOWNLOADS_FUNCTION_SEARCH);
586 return true; 629 return true;
587 } 630 }
588 631
589 DownloadsPauseFunction::DownloadsPauseFunction() {} 632 DownloadsPauseFunction::DownloadsPauseFunction() {}
590 DownloadsPauseFunction::~DownloadsPauseFunction() {} 633 DownloadsPauseFunction::~DownloadsPauseFunction() {}
591 634
592 bool DownloadsPauseFunction::RunImpl() { 635 bool DownloadsPauseFunction::RunImpl() {
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 RecordApiFunctions(DOWNLOADS_FUNCTION_GET_FILE_ICON); 826 RecordApiFunctions(DOWNLOADS_FUNCTION_GET_FILE_ICON);
784 SetResult(base::Value::CreateStringValue(url)); 827 SetResult(base::Value::CreateStringValue(url));
785 } 828 }
786 SendResponse(error_.empty()); 829 SendResponse(error_.empty());
787 } 830 }
788 831
789 ExtensionDownloadsEventRouter::ExtensionDownloadsEventRouter( 832 ExtensionDownloadsEventRouter::ExtensionDownloadsEventRouter(
790 Profile* profile, 833 Profile* profile,
791 DownloadManager* manager) 834 DownloadManager* manager)
792 : profile_(profile), 835 : profile_(profile),
793 manager_(manager) { 836 manager_(manager),
837 incognito_(profile_->HasOffTheRecordProfile() &&
838 (profile_ == profile_->GetOffTheRecordProfile())) {
794 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 839 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
795 DCHECK(profile_);
796 DCHECK(manager_);
797 manager_->AddObserver(this); 840 manager_->AddObserver(this);
798 } 841 }
799 842
800 ExtensionDownloadsEventRouter::~ExtensionDownloadsEventRouter() { 843 ExtensionDownloadsEventRouter::~ExtensionDownloadsEventRouter() {
801 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 844 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
802 if (manager_ != NULL) 845 if (manager_ != NULL)
803 manager_->RemoveObserver(this); 846 manager_->RemoveObserver(this);
804 for (ItemMap::const_iterator iter = downloads_.begin(); 847 for (ItemMap::const_iterator iter = downloads_.begin();
805 iter != downloads_.end(); ++iter) { 848 iter != downloads_.end(); ++iter) {
806 if (iter->second != NULL) 849 if (iter->second != NULL)
(...skipping 26 matching lines...) Expand all
833 DispatchEvent(extensions::event_names::kOnDownloadErased, 876 DispatchEvent(extensions::event_names::kOnDownloadErased,
834 base::Value::CreateIntegerValue(download_id)); 877 base::Value::CreateIntegerValue(download_id));
835 delete item_jsons_[download_id]; 878 delete item_jsons_[download_id];
836 item_jsons_.erase(download_id); 879 item_jsons_.erase(download_id);
837 delete on_changed_stats_[download_id]; 880 delete on_changed_stats_[download_id];
838 on_changed_stats_.erase(download_id); 881 on_changed_stats_.erase(download_id);
839 return; 882 return;
840 } 883 }
841 884
842 base::DictionaryValue* old_json = item_jsons_[download_id]; 885 base::DictionaryValue* old_json = item_jsons_[download_id];
843 scoped_ptr<base::DictionaryValue> new_json(DownloadItemToJSON(item)); 886 scoped_ptr<base::DictionaryValue> new_json(DownloadItemToJSON(
887 item, incognito_));
Randy Smith (Not in Mondays) 2012/08/02 17:52:17 Won't this produce the wrong result when we're dis
benjhayden 2012/08/13 15:08:09 We discussed offline how EDER handles incognito. T
844 scoped_ptr<base::DictionaryValue> delta(new base::DictionaryValue()); 888 scoped_ptr<base::DictionaryValue> delta(new base::DictionaryValue());
845 delta->SetInteger(kIdKey, download_id); 889 delta->SetInteger(kIdKey, download_id);
846 std::set<std::string> new_fields; 890 std::set<std::string> new_fields;
847 bool changed = false; 891 bool changed = false;
848 892
849 // For each field in the new json representation of the item except the 893 // For each field in the new json representation of the item except the
850 // bytesReceived field, if the field has changed from the previous old json, 894 // bytesReceived field, if the field has changed from the previous old json,
851 // set the differences in the |delta| object and remember that something 895 // set the differences in the |delta| object and remember that something
852 // significant changed. 896 // significant changed.
853 for (base::DictionaryValue::Iterator iter(*new_json.get()); 897 for (base::DictionaryValue::Iterator iter(*new_json.get());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 } 935 }
892 936
893 void ExtensionDownloadsEventRouter::OnDownloadCreated( 937 void ExtensionDownloadsEventRouter::OnDownloadCreated(
894 DownloadManager* manager, DownloadItem* download_item) { 938 DownloadManager* manager, DownloadItem* download_item) {
895 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 939 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
896 DCHECK(manager_ == manager); 940 DCHECK(manager_ == manager);
897 if (download_item->IsTemporary()) return; 941 if (download_item->IsTemporary()) return;
898 942
899 download_item->AddObserver(this); 943 download_item->AddObserver(this);
900 scoped_ptr<base::DictionaryValue> json_item( 944 scoped_ptr<base::DictionaryValue> json_item(
901 DownloadItemToJSON(download_item)); 945 DownloadItemToJSON(download_item, incognito_));
902 DispatchEvent(extensions::event_names::kOnDownloadCreated, 946 DispatchEvent(extensions::event_names::kOnDownloadCreated,
903 json_item->DeepCopy()); 947 json_item->DeepCopy());
904 int32 download_id = download_item->GetId(); 948 int32 download_id = download_item->GetId();
905 DCHECK(item_jsons_.find(download_id) == item_jsons_.end()); 949 DCHECK(item_jsons_.find(download_id) == item_jsons_.end());
906 on_changed_stats_[download_id] = new OnChangedStat(); 950 on_changed_stats_[download_id] = new OnChangedStat();
907 item_jsons_[download_id] = json_item.release(); 951 item_jsons_[download_id] = json_item.release();
908 downloads_[download_id] = download_item; 952 downloads_[download_id] = download_item;
909 } 953 }
910 954
911 void ExtensionDownloadsEventRouter::ManagerGoingDown( 955 void ExtensionDownloadsEventRouter::ManagerGoingDown(
912 DownloadManager* manager) { 956 DownloadManager* manager) {
913 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 957 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
914 manager_->RemoveObserver(this); 958 manager_->RemoveObserver(this);
915 manager_ = NULL; 959 manager_ = NULL;
916 } 960 }
917 961
918 void ExtensionDownloadsEventRouter::DispatchEvent( 962 void ExtensionDownloadsEventRouter::DispatchEvent(
919 const char* event_name, base::Value* arg) { 963 const char* event_name, base::Value* arg) {
920 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 964 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
921 base::ListValue args; 965 base::ListValue args;
922 args.Append(arg); 966 args.Append(arg);
923 std::string json_args; 967 std::string json_args;
924 base::JSONWriter::Write(&args, &json_args); 968 base::JSONWriter::Write(&args, &json_args);
925 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( 969 DispatchEventInternal(profile_, event_name, json_args);
926 event_name, 970 if (profile_->HasOffTheRecordProfile() &&
927 json_args, 971 (profile_ == profile_->GetOriginalProfile())) {
928 profile_, 972 DispatchEventInternal(
929 GURL(), 973 profile_->GetOffTheRecordProfile(), event_name, json_args);
930 extensions::EventFilteringInfo()); 974 }
931
932 DownloadsNotificationSource notification_source;
933 notification_source.event_name = event_name;
934 notification_source.profile = profile_;
935 content::NotificationService::current()->Notify(
936 chrome::NOTIFICATION_EXTENSION_DOWNLOADS_EVENT,
937 content::Source<DownloadsNotificationSource>(&notification_source),
938 content::Details<std::string>(&json_args));
939 } 975 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698