Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / content / browser / android / deferred_download_observer.h
blobf1df3178ba92d0586868b79de99e82d7f271ae5b
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_ANDROID_DEFERRED_DOWNLOAD_OBSERVER_H_
6 #define CONTENT_BROWSER_ANDROID_DEFERRED_DOWNLOAD_OBSERVER_H_
8 #include "base/callback.h"
9 #include "base/containers/scoped_ptr_hash_map.h"
10 #include "content/public/browser/web_contents_observer.h"
12 namespace content {
13 class WebContents;
15 // Class for handling deferred downloads inside a WebContents. In document
16 // mode, it is possible that a download starts before ContentViewCore gets
17 // created. This class listens to the WebContentsObserver::WasShown() method
18 // before running the download tasks to make sure ContentViewCore is attached
19 // to WebContents.
20 // TODO(qinmin): Remove this when java Tab object creation is no longer pending
21 // on Activity creation.
22 class DeferredDownloadObserver : public WebContentsObserver {
23 public:
24 DeferredDownloadObserver(WebContents* web_contents,
25 const base::Closure& deferred_download_cb);
26 ~DeferredDownloadObserver() override;
28 // WebContentsObserver method.
29 void WasShown() override;
30 void WebContentsDestroyed() override;
32 private:
33 // Callback to run when WebContents gets shown.
34 base::Closure deferred_download_cb_;
36 DISALLOW_COPY_AND_ASSIGN(DeferredDownloadObserver);
39 } // namespace content
41 #endif // CONTENT_BROWSER_ANDROID_DEFERRED_DOWNLOAD_OBSERVER_H_