OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_UI_WEBUI_SCREENSHOT_SOURCE_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_SCREENSHOT_SOURCE_H_ |
6 #define CHROME_BROWSER_UI_WEBUI_SCREENSHOT_SOURCE_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_SCREENSHOT_SOURCE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/memory/linked_ptr.h" | 13 #include "base/memory/linked_ptr.h" |
14 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 14 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
15 | 15 |
| 16 #if defined(OS_CHROMEOS) |
| 17 #include "chrome/browser/chromeos/gdata/gdata_errorcode.h" |
| 18 #include "chrome/browser/chromeos/gdata/gdata_files.h" |
| 19 #endif |
| 20 |
16 typedef std::vector<unsigned char> ScreenshotData; | 21 typedef std::vector<unsigned char> ScreenshotData; |
17 typedef linked_ptr<ScreenshotData> ScreenshotDataPtr; | 22 typedef linked_ptr<ScreenshotData> ScreenshotDataPtr; |
18 | 23 |
| 24 class FilePath; |
| 25 class Profile; |
| 26 |
19 // ScreenshotSource is the data source that serves screenshots (saved | 27 // ScreenshotSource is the data source that serves screenshots (saved |
20 // or current) to the bug report html ui. | 28 // or current) to the bug report html ui. |
21 class ScreenshotSource : public ChromeURLDataManager::DataSource { | 29 class ScreenshotSource : public ChromeURLDataManager::DataSource { |
22 public: | 30 public: |
23 explicit ScreenshotSource( | 31 explicit ScreenshotSource( |
24 std::vector<unsigned char>* current_screenshot); | 32 std::vector<unsigned char>* current_screenshot, |
| 33 Profile* profile); |
25 | 34 |
26 // Called when the network layer has requested a resource underneath | 35 // Called when the network layer has requested a resource underneath |
27 // the path we registered. | 36 // the path we registered. |
28 virtual void StartDataRequest(const std::string& path, | 37 virtual void StartDataRequest(const std::string& path, |
29 bool is_incognito, | 38 bool is_incognito, |
30 int request_id) OVERRIDE; | 39 int request_id) OVERRIDE; |
31 | 40 |
32 virtual std::string GetMimeType(const std::string&) const OVERRIDE; | 41 virtual std::string GetMimeType(const std::string&) const OVERRIDE; |
33 | 42 |
34 // Get the screenshot specified by the given relative path that we've cached | 43 // Get the screenshot specified by the given relative path that we've cached |
35 // from a previous request to the screenshots source. | 44 // from a previous request to the screenshots source. |
36 // Note: This method strips the query string from the given path. | 45 // Note: This method strips the query string from the given path. |
37 ScreenshotDataPtr GetCachedScreenshot(const std::string& screenshot_path); | 46 ScreenshotDataPtr GetCachedScreenshot(const std::string& screenshot_path); |
38 | 47 |
39 private: | 48 private: |
40 virtual ~ScreenshotSource(); | 49 virtual ~ScreenshotSource(); |
41 | 50 |
42 // Send the screenshot specified by the given relative path to the requestor. | 51 // Send the screenshot specified by the given relative path to the requestor. |
43 // This is the ancestor for SendSavedScreenshot and CacheAndSendScreenshot. | 52 // This is the ancestor for SendSavedScreenshot and CacheAndSendScreenshot. |
44 // All calls to send a screenshot should only call this method. | 53 // All calls to send a screenshot should only call this method. |
45 // Note: This method strips the query string from the given path. | 54 // Note: This method strips the query string from the given path. |
46 void SendScreenshot(const std::string& screenshot_path, int request_id); | 55 void SendScreenshot(const std::string& screenshot_path, int request_id); |
47 #if defined(OS_CHROMEOS) | 56 #if defined(OS_CHROMEOS) |
48 // Send a saved screenshot image file specified by the given screenshot path | 57 // Send a saved screenshot image file specified by the given screenshot path |
49 // to the requestor. | 58 // to the requestor. It has gdata-specific parameters to be used as its |
50 void SendSavedScreenshot(const std::string& screenshot_path, int request_id); | 59 // callback. |
| 60 void SendSavedScreenshot(const std::string& screenshot_path, |
| 61 int request_id, |
| 62 gdata::GDataFileError error, |
| 63 const FilePath& file, |
| 64 const std::string& mime_type, |
| 65 gdata::GDataFileType file_type); |
51 #endif | 66 #endif |
52 // Sends the screenshot data to the requestor while caching it locally to the | 67 // Sends the screenshot data to the requestor while caching it locally to the |
53 // class instance, indexed by path. | 68 // class instance, indexed by path. |
54 void CacheAndSendScreenshot(const std::string& screenshot_path, | 69 void CacheAndSendScreenshot(const std::string& screenshot_path, |
55 int request_id, | 70 int request_id, |
56 ScreenshotDataPtr bytes); | 71 ScreenshotDataPtr bytes); |
57 | 72 |
58 // Pointer to the screenshot data for the current screenshot. | 73 // Pointer to the screenshot data for the current screenshot. |
59 ScreenshotDataPtr current_screenshot_; | 74 ScreenshotDataPtr current_screenshot_; |
60 | 75 |
| 76 Profile* profile_; |
| 77 |
61 // Key: Relative path to the screenshot (including filename) | 78 // Key: Relative path to the screenshot (including filename) |
62 // Value: Pointer to the screenshot data associated with the path. | 79 // Value: Pointer to the screenshot data associated with the path. |
63 std::map<std::string, ScreenshotDataPtr> cached_screenshots_; | 80 std::map<std::string, ScreenshotDataPtr> cached_screenshots_; |
64 | 81 |
65 DISALLOW_COPY_AND_ASSIGN(ScreenshotSource); | 82 DISALLOW_COPY_AND_ASSIGN(ScreenshotSource); |
66 }; | 83 }; |
67 | 84 |
68 #endif // CHROME_BROWSER_UI_WEBUI_SCREENSHOT_SOURCE_H_ | 85 #endif // CHROME_BROWSER_UI_WEBUI_SCREENSHOT_SOURCE_H_ |
OLD | NEW |