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

Side by Side Diff: chrome/browser/download/download_test_observer.h

Issue 9570005: Added callback to DownloadUrl() so we can find download failures. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed CLANG issue. Created 8 years, 9 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 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TEST_OBSERVER_H_ 5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TEST_OBSERVER_H_
6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TEST_OBSERVER_H_ 6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TEST_OBSERVER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <set> 9 #include <set>
10 #include <vector>
10 11
11 #include "base/basictypes.h" 12 #include "base/basictypes.h"
12 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
13 #include "content/public/browser/download_item.h" 14 #include "content/public/browser/download_item.h"
14 #include "content/public/browser/download_manager.h" 15 #include "content/public/browser/download_manager.h"
16 #include "net/base/net_errors.h"
15 17
16 // Detects changes to the downloads after construction. 18 // Detects changes to the downloads after construction.
17 // Finishes when one of the following happens: 19 // Finishes when one of the following happens:
18 // - A specified number of downloads change to a terminal state (defined 20 // - A specified number of downloads change to a terminal state (defined
19 // as anything but IN_PROGRESS). 21 // as anything but IN_PROGRESS).
20 // - Specific events, such as a select file dialog. 22 // - Specific events, such as a select file dialog.
21 // Callers may either probe for the finished state, or wait on it. 23 // Callers may either probe for the finished state, or wait on it.
22 // 24 //
23 // TODO(rdsmith): Detect manager going down, remove pointer to 25 // TODO(rdsmith): Detect manager going down, remove pointer to
24 // DownloadManager, transition to finished. (For right now we 26 // DownloadManager, transition to finished. (For right now we
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 196
195 void PingIOThread(int cycle); 197 void PingIOThread(int cycle);
196 198
197 content::DownloadManager* download_manager_; 199 content::DownloadManager* download_manager_;
198 DownloadSet downloads_observed_; 200 DownloadSet downloads_observed_;
199 bool waiting_for_zero_inprogress_; 201 bool waiting_for_zero_inprogress_;
200 202
201 DISALLOW_COPY_AND_ASSIGN(DownloadTestFlushObserver); 203 DISALLOW_COPY_AND_ASSIGN(DownloadTestFlushObserver);
202 }; 204 };
203 205
206 // Waits for a callback indicating that the DownloadItem is about to be created,
207 // or that an error occurred and it won't be created.
208 class DownloadTestItemCreationObserver
209 : public base::RefCountedThreadSafe<DownloadTestItemCreationObserver> {
210 public:
211 DownloadTestItemCreationObserver();
212
213 void WaitForDownloadItemCreation();
214
215 content::DownloadId download_id() const {
216 return download_id_;
217 }
218 net::Error error() const { return error_; }
219 bool started() const { return called_back_count_ > 0; }
220 bool succeeded() const {
221 return started() && (error_ == net::OK);
222 }
223
224 const content::DownloadManager::OnStartedCallback callback();
225
226 private:
227 friend class base::RefCountedThreadSafe<DownloadTestItemCreationObserver>;
228
229 ~DownloadTestItemCreationObserver();
230
231 void DownloadItemCreationCallback(content::DownloadId download_id,
232 net::Error error);
233
234 // The download creation information we received.
235 content::DownloadId download_id_;
236
237 net::Error error_;
238
239 // Count of callbacks.
240 size_t called_back_count_;
241
242 // We are in the message loop.
243 bool waiting_;
244
245 DISALLOW_COPY_AND_ASSIGN(DownloadTestItemCreationObserver);
246 };
247
204 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TEST_OBSERVER_H_ 248 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TEST_OBSERVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698