Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_DATA_SOURCE_H_ | |
| 6 #define CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_DATA_SOURCE_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <map> | |
| 10 #include <string> | |
| 11 #include <utility> | |
| 12 | |
| 13 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | |
| 14 | |
| 15 template<typename T> struct LeakySingletonTraits; | |
| 16 | |
| 17 class PrintPreviewUI; | |
| 18 | |
| 19 namespace base { | |
| 20 class SharedMemory; | |
| 21 } | |
| 22 | |
| 23 // PrintPreviewDataSource serves data for chrome://print requests. | |
| 24 // | |
| 25 // PrintPreviewDataSource owns the data and is responsible for freeing it when | |
| 26 // either: | |
| 27 // a) there is a new data. | |
| 28 // b) When PrintPreviewDataSource is destroyed. | |
| 29 // | |
| 30 // The format for requesting data is as follows: | |
| 31 // chrome://print/print.pdf/<PrintPreviewUIAddrStr> | |
| 32 // | |
| 33 // Parameters (< > required): | |
| 34 // <PrintPreviewUIAddrStr> = Print preview UI identifier. | |
| 35 // | |
| 36 // Example: | |
| 37 // chrome://print/print.pdf/0x7f5470fbe510 | |
| 38 | |
| 39 class PrintPreviewDataSource : public ChromeURLDataManager::DataSource { | |
| 40 public: | |
| 41 // A SharedMemory that contains the data for print preview, | |
| 42 // and the size of the print preview data in bytes. | |
| 43 typedef std::pair<base::SharedMemory*, uint32> PrintPreviewData; | |
|
sky
2011/05/25 20:57:35
To make lifetime management easier, could this tak
kmadhusu
2011/05/25 23:45:21
I understand your concern. Just to be consistent w
sky
2011/05/26 17:40:41
Shouldn't you be striving for less error prone cod
| |
| 44 | |
| 45 typedef std::string PreviewUIAddrStr; | |
| 46 | |
| 47 // 1:1 relationship between PrintPreviewUI and preview data. | |
| 48 // Key: Print preview UI address string. | |
| 49 // Value: Preview data. | |
| 50 typedef std::map<PreviewUIAddrStr, PrintPreviewData> PreviewDataSrcMap; | |
| 51 | |
| 52 // Getter for the singleton. | |
| 53 static PrintPreviewDataSource* GetInstance(); | |
|
sky
2011/05/25 20:57:35
nit: constructor/destructor before static methods.
kmadhusu
2011/05/25 23:45:21
Done.
| |
| 54 | |
| 55 PrintPreviewDataSource(); | |
|
sky
2011/05/25 20:57:35
Is it possible to make the constructor private?
kmadhusu
2011/05/25 23:45:21
Since I am using "LeakySingleTonTraits", it needs
| |
| 56 virtual ~PrintPreviewDataSource(); | |
| 57 | |
| 58 // Remove the corresponding PrintPreviewUI entry from the map. | |
| 59 void RemoveEntry(const PreviewUIAddrStr& preview_ui_addr_str); | |
| 60 | |
| 61 // Set/Update the data entry in PreviewDataSrcMap. | |
| 62 void SetDataEntry(const PreviewUIAddrStr& preview_ui_addr_str, | |
| 63 const PrintPreviewData& data); | |
| 64 | |
| 65 // Get the data entry from PreviewDataSrcMap. | |
| 66 void GetDataEntry(const PreviewUIAddrStr& preview_ui_addr_str, | |
| 67 PrintPreviewData* data); | |
| 68 | |
| 69 // ChromeURLDataManager::DataSource implementation. | |
| 70 virtual void StartDataRequest(const std::string& path, | |
|
sky
2011/05/25 20:57:35
nit: Use OVERRIDE here and 73.
kmadhusu
2011/05/25 23:45:21
Done.
| |
| 71 bool is_incognito, | |
| 72 int request_id); | |
| 73 virtual std::string GetMimeType(const std::string& path) const; | |
| 74 | |
| 75 private: | |
| 76 friend struct LeakySingletonTraits<PrintPreviewDataSource>; | |
| 77 | |
| 78 PreviewDataSrcMap data_source_map_; | |
| 79 | |
| 80 DISALLOW_COPY_AND_ASSIGN(PrintPreviewDataSource); | |
| 81 }; | |
| 82 | |
| 83 #endif // CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_DATA_SOURCE_H_ | |
| OLD | NEW |