Chromium Code Reviews| Index: content/browser/android/download_controller.h |
| diff --git a/content/browser/android/download_controller.h b/content/browser/android/download_controller.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f07749ff3ed7e15628113125f65d130fc39a2b6f |
| --- /dev/null |
| +++ b/content/browser/android/download_controller.h |
| @@ -0,0 +1,113 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
|
jochen (gone - plz use gerrit)
2012/05/25 21:29:37
2012
nilesh
2012/05/25 23:10:22
Done.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +// This class pairs with DownloadController on Java side to forward requests |
| +// for GET downloads to the current DownloadListener. POST downloads are |
| +// handled on the native side. |
| +// |
| +// Both classes are Singleton classes. C++ object owns Java object. |
| +// |
| +// Call sequence |
| +// GET downloads: |
| +// DownloadController::NewGetDownload() => |
| +// DownloadController.newHttpGetDownload() => |
| +// DownloadListener.onDownloadStart() / |
| +// DownloadListener2.requestHttpGetDownload() |
| +// |
| + |
| +#ifndef CONTENT_BROWSER_ANDROID_DOWNLOAD_CONTROLLER_H_ |
|
jochen (gone - plz use gerrit)
2012/05/25 21:29:37
should this file go into content/browser/download/
nilesh
2012/05/25 23:10:22
We dont plan to have multiple files here.
Maybe co
|
| +#define CONTENT_BROWSER_ANDROID_DOWNLOAD_CONTROLLER_H_ |
| +#pragma once |
| + |
| +#include <string> |
| + |
| +#include "base/android/jni_helper.h" |
| +#include "base/memory/singleton.h" |
| +#include "content/public/browser/download_item.h" |
| +#include "googleurl/src/gurl.h" |
| + |
| +struct DownloadInfoAndroid; |
| + |
| +namespace content { |
| +struct GlobalRequestID; |
| +class RenderViewHost; |
| +class WebContents; |
| +} |
| + |
| +namespace net { |
| +class URLRequest; |
| +} |
| + |
| +class DownloadController : public content::DownloadItem::Observer { |
|
jochen (gone - plz use gerrit)
2012/05/25 21:29:37
code in src/content should be in the content names
nilesh
2012/05/25 23:10:22
Done.
|
| + public: |
| + static DownloadController* GetInstance(); |
| + |
| + // Called when DownloadController Java object is instantiated. |
| + void Init(JNIEnv* env, jobject obj); |
| + |
| + // Starts a new download request with Android. Should be called on the |
| + // UI thread. |
| + void NewGetDownload(content::RenderViewHost* source, |
| + int request_id); |
| + |
| + // Should be called when a POST download is started. Notifies the embedding |
| + // app about the download. Called on the UI thread. |
| + void OnPostDownloadStarted(content::WebContents* web_contents, |
| + content::DownloadItem* download_item); |
| + |
| + // DownloadItem::Observer interface. |
| + virtual void OnDownloadUpdated(content::DownloadItem* item) OVERRIDE; |
| + virtual void OnDownloadOpened(content::DownloadItem* item) OVERRIDE { } |
|
jochen (gone - plz use gerrit)
2012/05/25 21:29:37
virtual methods can't be inlined, therefore, the b
nilesh
2012/05/25 23:10:22
Done.
|
| + |
| + private: |
| + friend struct DefaultSingletonTraits<DownloadController>; |
| + DownloadController(); |
| + virtual ~DownloadController(); |
| + |
| + // Used to store all the information about an Android download. |
| + struct DownloadInfoAndroid { |
|
jochen (gone - plz use gerrit)
2012/05/25 21:29:37
definitions come before ctor/dtor
nilesh
2012/05/25 23:10:22
Done.
|
| + explicit DownloadInfoAndroid(net::URLRequest* request); |
| + ~DownloadInfoAndroid() {} |
| + |
| + // The URL from which we are downloading. This is the final URL after any |
| + // redirection by the server for |original_url_|. |
| + GURL url; |
| + // The original URL before any redirection by the server for this URL. |
| + GURL original_url; |
| + int64 total_bytes; |
| + std::string content_disposition; |
| + std::string original_mime_type; |
| + |
| + std::string user_agent; |
| + std::string cookie; |
| + |
| + content::WebContents* web_contents; |
| + // Default copy constructor is used for passing this struct by value. |
| + }; |
| + |
| + void PrepareDownloadInfo(const content::GlobalRequestID& global_id, |
| + int render_process_id, |
| + int render_view_id); |
| + |
| + void OnCookieResponse(DownloadInfoAndroid info, |
| + int render_process_id, |
| + int render_view_id, |
| + const std::string& cookie); |
| + |
| + void StartAndroidDownload(const DownloadInfoAndroid& info, |
| + int render_process_id, |
| + int render_view_id); |
| + |
| + jobject GetContentViewFromWebContents(content::WebContents* web_contents); |
| + jobject GetContentView(int render_process_id, int render_view_id); |
|
jochen (gone - plz use gerrit)
2012/05/25 21:29:37
empty line between method decls and variables
nilesh
2012/05/25 23:10:22
Done.
|
| + struct JavaObject; |
|
jochen (gone - plz use gerrit)
2012/05/25 21:29:37
type declarations come before methods
nilesh
2012/05/25 23:10:22
Done.
|
| + JavaObject* java_object_; |
| + |
| + // Creates Java object if it is not created already and returns it. |
| + JavaObject* java_object(); |
|
jochen (gone - plz use gerrit)
2012/05/25 21:29:37
methods before member variables
nilesh
2012/05/25 23:10:22
Done.
|
| +}; |
|
jochen (gone - plz use gerrit)
2012/05/25 21:29:37
disallow copy/assign
nilesh
2012/05/25 23:10:22
Done.
|
| + |
| +bool RegisterDownloadController(JNIEnv* env); |
|
jochen (gone - plz use gerrit)
2012/05/25 21:29:37
can this be a static method on DownloadController
nilesh
2012/05/25 23:10:22
Done.
|
| + |
| +#endif // CONTENT_BROWSER_ANDROID_DOWNLOAD_CONTROLLER_H_ |