Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / browser / appcache / appcache_internals_ui.h
blob3b2ddfa3f07c45f936e10c6a855e21ac9a92d265
1 // Copyright 2015 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.
5 #ifndef CONTENT_BROWSER_APPCACHE_APPCACHE_INTERNALS_UI_H_
6 #define CONTENT_BROWSER_APPCACHE_APPCACHE_INTERNALS_UI_H_
8 #include <list>
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "content/browser/appcache/appcache_group.h"
13 #include "content/browser/appcache/appcache_storage.h"
14 #include "content/browser/appcache/chrome_appcache_service.h"
15 #include "content/public/browser/storage_partition.h"
16 #include "content/public/browser/web_contents.h"
17 #include "content/public/browser/web_ui_controller.h"
18 #include "net/base/io_buffer.h"
20 namespace base {
21 class ListValue;
22 class FilePath;
25 namespace content {
27 // The implementation for the chrome://appcache-internals page.
28 // This implementation is based on the WebUI API and consists of a controller on
29 // The UI thread which communicates (through a Proxy) with the AppCacheService
30 // and AppCache storage which live on the IO thread.
31 class AppCacheInternalsUI : public WebUIController {
32 public:
33 explicit AppCacheInternalsUI(WebUI* web_ui);
34 ~AppCacheInternalsUI() override;
36 class Proxy : public AppCacheStorage::Delegate,
37 public base::RefCountedThreadSafe<Proxy> {
38 public:
39 friend class AppCacheInternalsUI;
41 struct ResponseEnquiry {
42 std::string manifest_url;
43 int64 group_id;
44 int64 response_id;
47 private:
48 friend class base::RefCountedThreadSafe<Proxy>;
50 Proxy(base::WeakPtr<AppCacheInternalsUI> appcache_internals_ui,
51 const base::FilePath& storage_partition);
52 ~Proxy() override;
54 void RequestAllAppCacheInfo();
55 void DeleteAppCache(const std::string& manifest_url);
56 void RequestAppCacheDetails(const std::string& manifest_url);
57 void RequestFileDetails(const ResponseEnquiry& response_enquiry);
58 void HandleFileDetailsRequest();
59 void OnAllAppCacheInfoReady(
60 scoped_refptr<AppCacheInfoCollection> collection,
61 int net_result_code);
62 void OnAppCacheInfoDeleted(const std::string& manifest_url,
63 int net_result_code);
64 void OnGroupLoaded(AppCacheGroup* appcache_group,
65 const GURL& manifest_gurl) override;
66 void OnResponseInfoLoaded(AppCacheResponseInfo* response_info,
67 int64 response_id) override;
68 void OnResponseDataReadComplete(
69 const ResponseEnquiry& response_enquiry,
70 scoped_refptr<AppCacheResponseInfo> response_info,
71 scoped_ptr<AppCacheResponseReader> reader,
72 scoped_refptr<net::IOBuffer> response_data,
73 int net_result_code);
74 void Initialize(
75 const scoped_refptr<ChromeAppCacheService>& chrome_appcache_service);
76 void Shutdown();
78 base::WeakPtr<AppCacheInternalsUI> appcache_internals_ui_;
79 base::WeakPtr<AppCacheServiceImpl> appcache_service_;
80 AppCacheStorage* appcache_storage_;
81 base::FilePath partition_path_;
82 scoped_refptr<AppCacheStorageReference> disabled_appcache_storage_ref_;
83 std::list<ResponseEnquiry> response_enquiries_;
84 bool preparing_response_;
85 bool shutdown_called_;
88 base::WeakPtr<AppCacheInternalsUI> AsWeakPtr() {
89 return weak_ptr_factory_.GetWeakPtr();
92 private:
93 void CreateProxyForPartition(StoragePartition* storage_partition);
94 // Commands from Javascript side.
95 void GetAllAppCache(const base::ListValue* args);
96 void DeleteAppCache(const base::ListValue* args);
97 void GetAppCacheDetails(const base::ListValue* args);
98 void GetFileDetails(const base::ListValue* args);
100 // Results from commands to be sent to Javascript.
101 void OnAllAppCacheInfoReady(scoped_refptr<AppCacheInfoCollection> collection,
102 const base::FilePath& partition_path);
103 void OnAppCacheInfoDeleted(const base::FilePath& partition_path,
104 const std::string& manifest_url,
105 bool deleted);
106 void OnAppCacheDetailsReady(
107 const base::FilePath& partition_path,
108 const std::string& manifest_url,
109 scoped_ptr<AppCacheResourceInfoVector> resource_info_vector);
110 void OnFileDetailsReady(const Proxy::ResponseEnquiry& response_enquiry,
111 scoped_refptr<AppCacheResponseInfo> response_info,
112 scoped_refptr<net::IOBuffer> response_data,
113 int data_length);
114 void OnFileDetailsFailed(const Proxy::ResponseEnquiry& response_enquiry,
115 int data_length);
117 BrowserContext* browser_context() {
118 return web_ui()->GetWebContents()->GetBrowserContext();
121 Proxy* GetProxyForPartitionPath(const base::FilePath& path);
122 std::list<scoped_refptr<Proxy>> appcache_proxies_;
123 base::WeakPtrFactory<AppCacheInternalsUI> weak_ptr_factory_;
125 DISALLOW_COPY_AND_ASSIGN(AppCacheInternalsUI);
128 } // namespace content
129 #endif