summaryrefslogtreecommitdiffstats
path: root/content/browser/android/deferred_download_observer.h
blob: f1df3178ba92d0586868b79de99e82d7f271ae5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_BROWSER_ANDROID_DEFERRED_DOWNLOAD_OBSERVER_H_
#define CONTENT_BROWSER_ANDROID_DEFERRED_DOWNLOAD_OBSERVER_H_

#include "base/callback.h"
#include "base/containers/scoped_ptr_hash_map.h"
#include "content/public/browser/web_contents_observer.h"

namespace content {
class WebContents;

// Class for handling deferred downloads inside a WebContents. In document
// mode, it is possible that a download starts before ContentViewCore gets
// created. This class listens to the WebContentsObserver::WasShown() method
// before running the download tasks to make sure ContentViewCore is attached
// to WebContents.
// TODO(qinmin): Remove this when java Tab object creation is no longer pending
// on Activity creation.
class DeferredDownloadObserver : public WebContentsObserver {
 public:
  DeferredDownloadObserver(WebContents* web_contents,
                           const base::Closure& deferred_download_cb);
  ~DeferredDownloadObserver() override;

  // WebContentsObserver method.
  void WasShown() override;
  void WebContentsDestroyed() override;

 private:
  // Callback to run when WebContents gets shown.
  base::Closure deferred_download_cb_;

  DISALLOW_COPY_AND_ASSIGN(DeferredDownloadObserver);
};

}  // namespace content

#endif  // CONTENT_BROWSER_ANDROID_DEFERRED_DOWNLOAD_OBSERVER_H_