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

Unified Diff: chrome/browser/chromeos/extensions/wallpaper_manager_api.h

Issue 10754014: Wallpaper manager backend APIs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix a crash when try to cancel previous request which had finished. Add more error message. Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/extensions/wallpaper_manager_api.h
diff --git a/chrome/browser/chromeos/extensions/wallpaper_manager_api.h b/chrome/browser/chromeos/extensions/wallpaper_manager_api.h
index cbe27ebc9a029edbe2c038a6f1c8f76669a29cab..8289545abc62ff9ef9fde60a5a336b5ac45ff573 100644
--- a/chrome/browser/chromeos/extensions/wallpaper_manager_api.h
+++ b/chrome/browser/chromeos/extensions/wallpaper_manager_api.h
@@ -5,6 +5,7 @@
#ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_WALLPAPER_MANAGER_API_H_
#define CHROME_BROWSER_CHROMEOS_EXTENSIONS_WALLPAPER_MANAGER_API_H_
+#include "ash/desktop_background/desktop_background_resources.h"
#include "base/file_path.h"
#include "base/memory/scoped_ptr.h"
#include "base/observer_list.h"
@@ -15,8 +16,31 @@
extern const char kWallpaperManagerDomain[];
-// Wallpaper manager API functions. Followup CL will add implementations of
-// some API functions.
+namespace {
+
+enum WallpaperErrorCode {
+ HTTP_SUCCESS = 200,
+ HTTP_CREATED = 201,
+ HTTP_FOUND = 302,
+ HTTP_NOT_MODIFIED = 304,
+ HTTP_RESUME_INCOMPLETE = 308,
+ HTTP_BAD_REQUEST = 400,
+ HTTP_UNAUTHORIZED = 401,
+ HTTP_FORBIDDEN = 403,
+ HTTP_NOT_FOUND = 404,
+ HTTP_CONFLICT = 409,
+ HTTP_LENGTH_REQUIRED = 411,
+ HTTP_PRECONDITION = 412,
+ HTTP_INTERNAL_SERVER_ERROR = 500,
+ HTTP_SERVICE_UNAVAILABLE = 503,
+ WALLPAPER_NO_CONNECTION = -100,
+ WALLPAPER_FILE_ERROR = -101,
+};
+
+const int64 kBytesWallpaperDownloadProgressReportInterval = 10240;
Mihai Parparita -not on Chrome 2012/07/16 23:14:25 Seems like this can just be in the .cc file.
bshe 2012/07/18 18:28:56 removed. On 2012/07/16 23:14:25, Mihai Parparita
+
+} // namespace
+
namespace wallpaper_manager_util {
// Opens wallpaper manager application.
@@ -24,4 +48,92 @@ void OpenWallpaperManager();
} // namespace wallpaper_manager_util
+// Wallpaper manager strings.
+class WallpaperManagerStringsFunction : public SyncExtensionFunction {
+ public:
+ DECLARE_EXTENSION_FUNCTION_NAME("wallpaperManagerPrivate.getStrings");
+
+ protected:
+ virtual ~WallpaperManagerStringsFunction() {}
+
+ // SyncExtensionFunction overrides.
+ virtual bool RunImpl() OVERRIDE;
+};
+
+// Sets wallpaper to the image downloaded from URL.
+class WallpaperManagerSetWallpaperFunction : public AsyncExtensionFunction {
+ public:
+ DECLARE_EXTENSION_FUNCTION_NAME("wallpaperManagerPrivate.setWallpaper");
Mihai Parparita -not on Chrome 2012/07/16 23:14:25 The file name generally matches the API namespace
bshe 2012/07/18 18:28:56 Done.
+
+ protected:
+ virtual ~WallpaperManagerSetWallpaperFunction();
+
+ // SyncExtensionFunction overrides.
+ virtual bool RunImpl() OVERRIDE;
+
+ private:
+ // This class is a wrapper class for URLFetcher. It has a ref counted pointer
Mihai Parparita -not on Chrome 2012/07/16 23:14:25 To make the header file more readable/hide interna
bshe 2012/07/18 18:28:56 Removed the class in new patch. On 2012/07/16 23:
+ // to class WallpaperManagerSetWallpaperFunction. So the instance of that
+ // class did not delete itself before fetching complete. We need to delete
+ // this wrapper class to release the ref counted pointer when fetch completed
+ // or canceled.
+ class WallpaperFetcher : public net::URLFetcherDelegate {
+ public:
+ explicit WallpaperFetcher(
+ scoped_refptr<WallpaperManagerSetWallpaperFunction> function);
+
+ void Cancel();
+
+ void Start(const GURL& wallpaper_url,
+ const FilePath& file_path);
+
+ private:
+ // URLFetcherDelegate overrides:
+ virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE ;
+ virtual void OnURLFetchDownloadProgress(const net::URLFetcher* source,
+ int64 current,
+ int64 total) OVERRIDE;
+
+ scoped_refptr<WallpaperManagerSetWallpaperFunction> function_;
+ scoped_ptr<net::URLFetcher> fetcher_;
+
+ DISALLOW_COPY_AND_ASSIGN(WallpaperFetcher);
+ };
+
+ void OnDownloadComplete(const net::URLFetcher* source);
+ void OnDownloadProgress(const net::URLFetcher* source,
+ int64 current,
+ int64 total);
+
+ // Requests wallpaper from local file if cached.
+ void RequestOnFileThread(const std::string& source_url);
+
+ // Changes wallpaper to image at |file_path|.
+ void SetWallpaperOnUIThread(const FilePath& file_path);
+
+ // Sets up the url_fetcher on UI thread.
+ void SetupFetcherOnUIThread(const GURL& wallpaper_url);
+
+ // Returns wallpaper manager specific error code.
+ WallpaperErrorCode GetErrorCode(const net::URLFetcher* source) const;
+
+ // Dispatch DownloadErrorEvent to wallpaper manager extension.
+ void DispatchErrorEvent(WallpaperErrorCode code);
+
+ // Directory to save downloaded wallpapers.
+ FilePath wallpaper_dir_;
+
+ // Layout of the downloaded wallpaper.
+ ash::WallpaperLayout layout_;
+
+ // Instance of WallpaperFetcher.
+ static WallpaperFetcher* fetcher_;
+
+ // The email address of logged in user.
+ std::string email_;
+
+ base::TimeTicks tick_wallpaper_download_start_;
+ int64 bytes_wallpaper_download_progress_last_reported_;
+};
+
#endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_WALLPAPER_MANAGER_API_H_

Powered by Google App Engine
This is Rietveld 408576698