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

Side by Side Diff: chrome/browser/automation/testing_automation_provider.cc

Issue 6159001: Modifying some downloads hooks to act per-window (so that incognito windows c... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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
« no previous file with comments | « no previous file | chrome/test/functional/downloads.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/automation/testing_automation_provider.h" 5 #include "chrome/browser/automation/testing_automation_provider.h"
6 6
7 #include "app/message_box_flags.h" 7 #include "app/message_box_flags.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 2503 matching lines...) Expand 10 before | Expand all | Expand 10 after
2514 reply.SendSuccess(NULL); 2514 reply.SendSuccess(NULL);
2515 } 2515 }
2516 2516
2517 // Sample json input: { "command": "GetDownloadsInfo" } 2517 // Sample json input: { "command": "GetDownloadsInfo" }
2518 // Refer chrome/test/pyautolib/download_info.py for sample json output. 2518 // Refer chrome/test/pyautolib/download_info.py for sample json output.
2519 void TestingAutomationProvider::GetDownloadsInfo(Browser* browser, 2519 void TestingAutomationProvider::GetDownloadsInfo(Browser* browser,
2520 DictionaryValue* args, 2520 DictionaryValue* args,
2521 IPC::Message* reply_message) { 2521 IPC::Message* reply_message) {
2522 AutomationJSONReply reply(this, reply_message); 2522 AutomationJSONReply reply(this, reply_message);
2523 2523
2524 if (!profile_->HasCreatedDownloadManager()) { 2524 if (!browser->profile()->HasCreatedDownloadManager()) {
2525 reply.SendError("no download manager"); 2525 reply.SendError("no download manager");
2526 return; 2526 return;
2527 } 2527 }
2528 2528
2529 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); 2529 scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
2530 std::vector<DownloadItem*> downloads; 2530 std::vector<DownloadItem*> downloads;
2531 profile_->GetDownloadManager()->GetAllDownloads(FilePath(), &downloads); 2531 browser->profile()->GetDownloadManager()->
2532 GetAllDownloads(FilePath(), &downloads);
2532 2533
2533 ListValue* list_of_downloads = new ListValue; 2534 ListValue* list_of_downloads = new ListValue;
2534 for (std::vector<DownloadItem*>::iterator it = downloads.begin(); 2535 for (std::vector<DownloadItem*>::iterator it = downloads.begin();
2535 it != downloads.end(); 2536 it != downloads.end();
2536 it++) { // Fill info about each download item. 2537 it++) { // Fill info about each download item.
2537 list_of_downloads->Append(GetDictionaryFromDownloadItem(*it)); 2538 list_of_downloads->Append(GetDictionaryFromDownloadItem(*it));
2538 } 2539 }
2539 return_value->Set("downloads", list_of_downloads); 2540 return_value->Set("downloads", list_of_downloads);
2540 reply.SendSuccess(return_value.get()); 2541 reply.SendSuccess(return_value.get());
2541 // All value objects allocated above are owned by |return_value| 2542 // All value objects allocated above are owned by |return_value|
2542 // and get freed by it. 2543 // and get freed by it.
2543 } 2544 }
2544 2545
2545 void TestingAutomationProvider::WaitForDownloadsToComplete( 2546 void TestingAutomationProvider::WaitForDownloadsToComplete(
2546 Browser* browser, 2547 Browser* browser,
2547 DictionaryValue* args, 2548 DictionaryValue* args,
2548 IPC::Message* reply_message) { 2549 IPC::Message* reply_message) {
2549 2550
2550 // Look for a quick return. 2551 // Look for a quick return.
2551 if (!profile_->HasCreatedDownloadManager()) { 2552 if (!browser->profile()->HasCreatedDownloadManager()) {
2552 // No download manager. 2553 // No download manager.
2553 AutomationJSONReply(this, reply_message).SendSuccess(NULL); 2554 AutomationJSONReply(this, reply_message).SendSuccess(NULL);
2554 return; 2555 return;
2555 } 2556 }
2556 std::vector<DownloadItem*> downloads; 2557 std::vector<DownloadItem*> downloads;
2557 profile_->GetDownloadManager()->GetCurrentDownloads(FilePath(), &downloads); 2558 browser->profile()->GetDownloadManager()->
2559 GetCurrentDownloads(FilePath(), &downloads);
2558 if (downloads.empty()) { 2560 if (downloads.empty()) {
2559 AutomationJSONReply(this, reply_message).SendSuccess(NULL); 2561 AutomationJSONReply(this, reply_message).SendSuccess(NULL);
2560 return; 2562 return;
2561 } 2563 }
2562
2563 // The observer owns itself. When the last observed item pings, it 2564 // The observer owns itself. When the last observed item pings, it
2564 // deletes itself. 2565 // deletes itself.
2565 AutomationProviderDownloadItemObserver* item_observer = 2566 AutomationProviderDownloadItemObserver* item_observer =
2566 new AutomationProviderDownloadItemObserver( 2567 new AutomationProviderDownloadItemObserver(
2567 this, reply_message, downloads.size()); 2568 this, reply_message, downloads.size());
2568 for (std::vector<DownloadItem*>::iterator i = downloads.begin(); 2569 for (std::vector<DownloadItem*>::iterator i = downloads.begin();
2569 i != downloads.end(); 2570 i != downloads.end();
2570 i++) { 2571 i++) {
2571 (*i)->AddObserver(item_observer); 2572 (*i)->AddObserver(item_observer);
2572 } 2573 }
(...skipping 22 matching lines...) Expand all
2595 2596
2596 // See PerformActionOnDownload() in chrome/test/pyautolib/pyauto.py for sample 2597 // See PerformActionOnDownload() in chrome/test/pyautolib/pyauto.py for sample
2597 // json input and output. 2598 // json input and output.
2598 void TestingAutomationProvider::PerformActionOnDownload( 2599 void TestingAutomationProvider::PerformActionOnDownload(
2599 Browser* browser, 2600 Browser* browser,
2600 DictionaryValue* args, 2601 DictionaryValue* args,
2601 IPC::Message* reply_message) { 2602 IPC::Message* reply_message) {
2602 int id; 2603 int id;
2603 std::string action; 2604 std::string action;
2604 2605
2605 if (!profile_->HasCreatedDownloadManager()) { 2606 if (!browser->profile()->HasCreatedDownloadManager()) {
2606 AutomationJSONReply(this, reply_message).SendError("No download manager."); 2607 AutomationJSONReply(this, reply_message).SendError("No download manager.");
2607 return; 2608 return;
2608 } 2609 }
2609 if (!args->GetInteger("id", &id) || !args->GetString("action", &action)) { 2610 if (!args->GetInteger("id", &id) || !args->GetString("action", &action)) {
2610 AutomationJSONReply(this, reply_message).SendError( 2611 AutomationJSONReply(this, reply_message).SendError(
2611 "Must include int id and string action."); 2612 "Must include int id and string action.");
2612 return; 2613 return;
2613 } 2614 }
2614 2615
2615 DownloadManager* download_manager = profile_->GetDownloadManager(); 2616 DownloadManager* download_manager = browser->profile()->GetDownloadManager();
2616 DownloadItem* selected_item = GetDownloadItemFromId(id, download_manager); 2617 DownloadItem* selected_item = GetDownloadItemFromId(id, download_manager);
2617 if (!selected_item) { 2618 if (!selected_item) {
2618 AutomationJSONReply(this, reply_message).SendError( 2619 AutomationJSONReply(this, reply_message).SendError(
2619 StringPrintf("No download with an id of %d\n", id)); 2620 StringPrintf("No download with an id of %d\n", id));
2620 return; 2621 return;
2621 } 2622 }
2622 2623
2623 if (action == "open") { 2624 if (action == "open") {
2624 selected_item->AddObserver( 2625 selected_item->AddObserver(
2625 new AutomationProviderDownloadUpdatedObserver( 2626 new AutomationProviderDownloadUpdatedObserver(
(...skipping 1891 matching lines...) Expand 10 before | Expand all | Expand 10 after
4517 // If you change this, update Observer for NotificationType::SESSION_END 4518 // If you change this, update Observer for NotificationType::SESSION_END
4518 // below. 4519 // below.
4519 MessageLoop::current()->PostTask(FROM_HERE, 4520 MessageLoop::current()->PostTask(FROM_HERE,
4520 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); 4521 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider));
4521 } 4522 }
4522 } 4523 }
4523 4524
4524 void TestingAutomationProvider::OnRemoveProvider() { 4525 void TestingAutomationProvider::OnRemoveProvider() {
4525 AutomationProviderList::GetInstance()->RemoveProvider(this); 4526 AutomationProviderList::GetInstance()->RemoveProvider(this);
4526 } 4527 }
OLDNEW
« no previous file with comments | « no previous file | chrome/test/functional/downloads.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698