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/automation/testing_automation_provider.h" | 5 #include "chrome/browser/automation/testing_automation_provider.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 2924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2935 if (downloads.empty()) { | 2935 if (downloads.empty()) { |
2936 AutomationJSONReply(this, reply_message).SendSuccess(NULL); | 2936 AutomationJSONReply(this, reply_message).SendSuccess(NULL); |
2937 return; | 2937 return; |
2938 } | 2938 } |
2939 // The observer owns itself. When the last observed item pings, it | 2939 // The observer owns itself. When the last observed item pings, it |
2940 // deletes itself. | 2940 // deletes itself. |
2941 AutomationProviderDownloadItemObserver* item_observer = | 2941 AutomationProviderDownloadItemObserver* item_observer = |
2942 new AutomationProviderDownloadItemObserver( | 2942 new AutomationProviderDownloadItemObserver( |
2943 this, reply_message, downloads.size()); | 2943 this, reply_message, downloads.size()); |
2944 for (std::vector<DownloadItem*>::iterator i = downloads.begin(); | 2944 for (std::vector<DownloadItem*>::iterator i = downloads.begin(); |
2945 i != downloads.end(); | 2945 i != downloads.end(); ++i) { |
2946 i++) { | |
2947 (*i)->AddObserver(item_observer); | 2946 (*i)->AddObserver(item_observer); |
2948 } | 2947 } |
2948 // It's possible that pending downloads may have completed before the observer | |
Paweł Hajdan Jr.
2011/08/01 22:42:10
Seems hacky. How about starting the new download o
Nirnimesh
2011/08/01 22:49:24
In a perfect world, yes. But the flakes in the dow
dennis_jeffrey
2011/08/02 00:04:53
The suggested approach works well in the case wher
Paweł Hajdan Jr.
2011/08/02 16:53:23
Please show me the bugs and I can fix them. Let's
Paweł Hajdan Jr.
2011/08/02 16:53:23
This is a known problem with pyauto. I see the fol
| |
2949 // above has been completely set up. Handle this case by checking again and | |
2950 // returning if there are no pending downloads. | |
2951 browser->profile()->GetDownloadManager()-> | |
2952 GetCurrentDownloads(FilePath(), &downloads); | |
2953 if (downloads.empty()) { | |
2954 delete item_observer; | |
2955 AutomationJSONReply(this, reply_message).SendSuccess(NULL); | |
2956 } | |
2949 } | 2957 } |
2950 | 2958 |
2951 namespace { | 2959 namespace { |
2952 | 2960 |
2953 DownloadItem* GetDownloadItemFromId(int id, DownloadManager* download_manager) { | 2961 DownloadItem* GetDownloadItemFromId(int id, DownloadManager* download_manager) { |
2954 std::vector<DownloadItem*> downloads; | 2962 std::vector<DownloadItem*> downloads; |
2955 download_manager->GetAllDownloads(FilePath(), &downloads); | 2963 download_manager->GetAllDownloads(FilePath(), &downloads); |
2956 DownloadItem* selected_item = NULL; | 2964 DownloadItem* selected_item = NULL; |
2957 | 2965 |
2958 for (std::vector<DownloadItem*>::iterator it = downloads.begin(); | 2966 for (std::vector<DownloadItem*>::iterator it = downloads.begin(); |
(...skipping 3181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6140 IPC::ParamTraits<std::vector<GURL> >::Write(reply_message_, redirects_gurl); | 6148 IPC::ParamTraits<std::vector<GURL> >::Write(reply_message_, redirects_gurl); |
6141 | 6149 |
6142 Send(reply_message_); | 6150 Send(reply_message_); |
6143 redirect_query_ = 0; | 6151 redirect_query_ = 0; |
6144 reply_message_ = NULL; | 6152 reply_message_ = NULL; |
6145 } | 6153 } |
6146 | 6154 |
6147 void TestingAutomationProvider::OnRemoveProvider() { | 6155 void TestingAutomationProvider::OnRemoveProvider() { |
6148 AutomationProviderList::GetInstance()->RemoveProvider(this); | 6156 AutomationProviderList::GetInstance()->RemoveProvider(this); |
6149 } | 6157 } |
OLD | NEW |