summaryrefslogtreecommitdiffstats
path: root/content/browser/appcache/appcache_internals_ui.h
blob: 3b2ddfa3f07c45f936e10c6a855e21ac9a92d265 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Copyright 2015 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 CONTENT_BROWSER_APPCACHE_APPCACHE_INTERNALS_UI_H_
#define CONTENT_BROWSER_APPCACHE_APPCACHE_INTERNALS_UI_H_

#include <list>

#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "content/browser/appcache/appcache_group.h"
#include "content/browser/appcache/appcache_storage.h"
#include "content/browser/appcache/chrome_appcache_service.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui_controller.h"
#include "net/base/io_buffer.h"

namespace base {
class ListValue;
class FilePath;
}

namespace content {

// The implementation for the chrome://appcache-internals page.
// This implementation is based on the WebUI API and consists of a controller on
// The UI thread which communicates (through a Proxy) with the AppCacheService
// and AppCache storage which live on the IO thread.
class AppCacheInternalsUI : public WebUIController {
 public:
  explicit AppCacheInternalsUI(WebUI* web_ui);
  ~AppCacheInternalsUI() override;

  class Proxy : public AppCacheStorage::Delegate,
                public base::RefCountedThreadSafe<Proxy> {
   public:
    friend class AppCacheInternalsUI;

    struct ResponseEnquiry {
      std::string manifest_url;
      int64 group_id;
      int64 response_id;
    };

   private:
    friend class base::RefCountedThreadSafe<Proxy>;

    Proxy(base::WeakPtr<AppCacheInternalsUI> appcache_internals_ui,
          const base::FilePath& storage_partition);
    ~Proxy() override;

    void RequestAllAppCacheInfo();
    void DeleteAppCache(const std::string& manifest_url);
    void RequestAppCacheDetails(const std::string& manifest_url);
    void RequestFileDetails(const ResponseEnquiry& response_enquiry);
    void HandleFileDetailsRequest();
    void OnAllAppCacheInfoReady(
        scoped_refptr<AppCacheInfoCollection> collection,
        int net_result_code);
    void OnAppCacheInfoDeleted(const std::string& manifest_url,
                               int net_result_code);
    void OnGroupLoaded(AppCacheGroup* appcache_group,
                       const GURL& manifest_gurl) override;
    void OnResponseInfoLoaded(AppCacheResponseInfo* response_info,
                              int64 response_id) override;
    void OnResponseDataReadComplete(
        const ResponseEnquiry& response_enquiry,
        scoped_refptr<AppCacheResponseInfo> response_info,
        scoped_ptr<AppCacheResponseReader> reader,
        scoped_refptr<net::IOBuffer> response_data,
        int net_result_code);
    void Initialize(
        const scoped_refptr<ChromeAppCacheService>& chrome_appcache_service);
    void Shutdown();

    base::WeakPtr<AppCacheInternalsUI> appcache_internals_ui_;
    base::WeakPtr<AppCacheServiceImpl> appcache_service_;
    AppCacheStorage* appcache_storage_;
    base::FilePath partition_path_;
    scoped_refptr<AppCacheStorageReference> disabled_appcache_storage_ref_;
    std::list<ResponseEnquiry> response_enquiries_;
    bool preparing_response_;
    bool shutdown_called_;
  };

  base::WeakPtr<AppCacheInternalsUI> AsWeakPtr() {
    return weak_ptr_factory_.GetWeakPtr();
  }

 private:
  void CreateProxyForPartition(StoragePartition* storage_partition);
  // Commands from Javascript side.
  void GetAllAppCache(const base::ListValue* args);
  void DeleteAppCache(const base::ListValue* args);
  void GetAppCacheDetails(const base::ListValue* args);
  void GetFileDetails(const base::ListValue* args);

  // Results from commands to be sent to Javascript.
  void OnAllAppCacheInfoReady(scoped_refptr<AppCacheInfoCollection> collection,
                              const base::FilePath& partition_path);
  void OnAppCacheInfoDeleted(const base::FilePath& partition_path,
                             const std::string& manifest_url,
                             bool deleted);
  void OnAppCacheDetailsReady(
      const base::FilePath& partition_path,
      const std::string& manifest_url,
      scoped_ptr<AppCacheResourceInfoVector> resource_info_vector);
  void OnFileDetailsReady(const Proxy::ResponseEnquiry& response_enquiry,
                          scoped_refptr<AppCacheResponseInfo> response_info,
                          scoped_refptr<net::IOBuffer> response_data,
                          int data_length);
  void OnFileDetailsFailed(const Proxy::ResponseEnquiry& response_enquiry,
                           int data_length);

  BrowserContext* browser_context() {
    return web_ui()->GetWebContents()->GetBrowserContext();
  }

  Proxy* GetProxyForPartitionPath(const base::FilePath& path);
  std::list<scoped_refptr<Proxy>> appcache_proxies_;
  base::WeakPtrFactory<AppCacheInternalsUI> weak_ptr_factory_;

  DISALLOW_COPY_AND_ASSIGN(AppCacheInternalsUI);
};

}  // namespace content
#endif