| 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 <string> |   9 #include <string> | 
|   9 #include <vector> |  10 #include <vector> | 
|  10  |  11  | 
|  11 #include "base/basictypes.h" |  12 #include "base/basictypes.h" | 
 |  13 #include "base/memory/linked_ptr.h" | 
|  12 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |  14 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 
|  13  |  15  | 
 |  16 typedef std::vector<unsigned char> ScreenshotData; | 
 |  17 typedef linked_ptr<ScreenshotData> ScreenshotDataPtr; | 
 |  18  | 
|  14 // ScreenshotSource is the data source that serves screenshots (saved |  19 // ScreenshotSource is the data source that serves screenshots (saved | 
|  15 // or current) to the bug report html ui |  20 // or current) to the bug report html ui. | 
|  16 class ScreenshotSource : public ChromeURLDataManager::DataSource { |  21 class ScreenshotSource : public ChromeURLDataManager::DataSource { | 
|  17  public: |  22  public: | 
|  18   explicit ScreenshotSource( |  23   explicit ScreenshotSource( | 
|  19       std::vector<unsigned char>* current_screenshot); |  24       std::vector<unsigned char>* current_screenshot); | 
|  20  |  25  | 
|  21   // Called when the network layer has requested a resource underneath |  26   // Called when the network layer has requested a resource underneath | 
|  22   // the path we registered. |  27   // the path we registered. | 
|  23   virtual void StartDataRequest(const std::string& path, |  28   virtual void StartDataRequest(const std::string& path, | 
|  24                                 bool is_incognito, |  29                                 bool is_incognito, | 
|  25                                 int request_id); |  30                                 int request_id); | 
|  26  |  31  | 
|  27   virtual std::string GetMimeType(const std::string&) const; |  32   virtual std::string GetMimeType(const std::string&) const; | 
|  28  |  33  | 
|  29   std::vector<unsigned char> GetScreenshot(const std::string& path); |  34   // Get the screenshot specified by the given relative path that we've cached | 
 |  35   // from a previous request to the screenshots source. | 
 |  36   // Note: This method strips the query string from the given path. | 
 |  37   ScreenshotDataPtr GetCachedScreenshot(const std::string& screenshot_path); | 
|  30  |  38  | 
|  31  private: |  39  private: | 
|  32   virtual ~ScreenshotSource(); |  40   virtual ~ScreenshotSource(); | 
|  33  |  41  | 
|  34   std::vector<unsigned char> current_screenshot_; |  42   // Send the screenshot specified by the given relative path to the requestor. | 
 |  43   // This is the ancestor for SendSavedScreenshot and CacheAndSendScreenshot. | 
 |  44   // All calls to send a screenshot should only call this method. | 
 |  45   // Note: This method strips the query string from the given path. | 
 |  46   void SendScreenshot(const std::string& screenshot_path, int request_id); | 
 |  47 #if defined(OS_CHROMEOS) | 
 |  48   // Send a saved screenshot image file specified by the given screenshot path | 
 |  49   // to the requestor. | 
 |  50   void SendSavedScreenshot(const std::string& screenshot_path, int request_id); | 
 |  51 #endif | 
 |  52   // Sends the screenshot data to the requestor while caching it locally to the | 
 |  53   // class instance, indexed by path. | 
 |  54   void CacheAndSendScreenshot(const std::string& screenshot_path, | 
 |  55                               int request_id, | 
 |  56                               ScreenshotDataPtr bytes); | 
 |  57  | 
 |  58   // Pointer to the screenshot data for the current screenshot. | 
 |  59   ScreenshotDataPtr current_screenshot_; | 
 |  60  | 
 |  61   // Key: Relative path to the screenshot (including filename) | 
 |  62   // Value: Pointer to the screenshot data associated with the path. | 
 |  63   std::map<std::string, ScreenshotDataPtr> cached_screenshots_; | 
|  35  |  64  | 
|  36   DISALLOW_COPY_AND_ASSIGN(ScreenshotSource); |  65   DISALLOW_COPY_AND_ASSIGN(ScreenshotSource); | 
|  37 }; |  66 }; | 
|  38  |  67  | 
|  39 #endif  // CHROME_BROWSER_UI_WEBUI_SCREENSHOT_SOURCE_H_ |  68 #endif  // CHROME_BROWSER_UI_WEBUI_SCREENSHOT_SOURCE_H_ | 
| OLD | NEW |