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

Unified Diff: chrome/browser/ui/webui/print_preview_data_source.h

Issue 7063030: PrintPreview: Print Preview is not staying associated with initiator renderer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix win compile error Created 9 years, 7 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/ui/webui/print_preview_data_source.h
diff --git a/chrome/browser/ui/webui/print_preview_data_source.h b/chrome/browser/ui/webui/print_preview_data_source.h
new file mode 100644
index 0000000000000000000000000000000000000000..b30716e561d70c2b69c2629700511599e801f639
--- /dev/null
+++ b/chrome/browser/ui/webui/print_preview_data_source.h
@@ -0,0 +1,84 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_DATA_SOURCE_H_
+#define CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_DATA_SOURCE_H_
+#pragma once
+
+#include <map>
+#include <string>
+#include <utility>
+
+#include "base/compiler_specific.h"
+#include "chrome/browser/ui/webui/chrome_url_data_manager.h"
+
+template<typename T> struct LeakySingletonTraits;
+
+class PrintPreviewUI;
+
+namespace base {
+class SharedMemory;
+}
+
+// PrintPreviewDataSource serves data for chrome://print requests.
+//
+// PrintPreviewDataSource owns the data and is responsible for freeing it when
+// either:
+// a) there is a new data.
+// b) When PrintPreviewDataSource is destroyed.
+//
+// The format for requesting data is as follows:
+// chrome://print/print.pdf/<PrintPreviewUIAddrStr>
+//
+// Parameters (< > required):
+// <PrintPreviewUIAddrStr> = Print preview UI identifier.
+//
+// Example:
+// chrome://print/print.pdf/0x7f5470fbe510
Lei Zhang 2011/05/26 01:48:31 That's a weird looking URL. Can we do chrome://pri
kmadhusu 2011/05/26 15:51:22 Done.
+
+class PrintPreviewDataSource : public ChromeURLDataManager::DataSource {
+ public:
+ // A SharedMemory that contains the data for print preview,
+ // and the size of the print preview data in bytes.
+ typedef std::pair<base::SharedMemory*, uint32> PrintPreviewData;
+
+ typedef std::string PreviewUIAddrStr;
Lei Zhang 2011/05/26 01:48:31 can we not have this typedef and just use std::str
kmadhusu 2011/05/26 15:51:22 Done.
+
+ // 1:1 relationship between PrintPreviewUI and preview data.
+ // Key: Print preview UI address string.
+ // Value: Preview data.
+ typedef std::map<PreviewUIAddrStr, PrintPreviewData> PreviewDataSrcMap;
+
+ PrintPreviewDataSource();
+ virtual ~PrintPreviewDataSource();
+
+ // Getter for the singleton.
+ static PrintPreviewDataSource* GetInstance();
+
+ // Remove the corresponding PrintPreviewUI entry from the map.
+ void RemoveEntry(const PreviewUIAddrStr& preview_ui_addr_str);
Lei Zhang 2011/05/26 01:48:31 nit: Can you put them in a more logical order? Get
kmadhusu 2011/05/26 15:51:22 Done.
+
+ // Set/Update the data entry in PreviewDataSrcMap.
+ void SetDataEntry(const PreviewUIAddrStr& preview_ui_addr_str,
+ const PrintPreviewData& data);
+
+ // Get the data entry from PreviewDataSrcMap.
+ void GetDataEntry(const PreviewUIAddrStr& preview_ui_addr_str,
+ PrintPreviewData* data);
+
+ // ChromeURLDataManager::DataSource implementation.
+ virtual void StartDataRequest(const std::string& path,
+ bool is_incognito,
+ int request_id) OVERRIDE;
+ virtual std::string GetMimeType(const std::string& path) const OVERRIDE;
+
+ private:
+ friend struct LeakySingletonTraits<PrintPreviewDataSource>;
Lei Zhang 2011/05/26 01:48:31 Use DefaultSingletonTraits here. Then you can make
kmadhusu 2011/05/26 15:51:22 Removed the singleton traits.
+
+ PreviewDataSrcMap data_source_map_;
+
+ DISALLOW_COPY_AND_ASSIGN(PrintPreviewDataSource);
+};
+
+#endif // CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_DATA_SOURCE_H_

Powered by Google App Engine
This is Rietveld 408576698