chromeos: bluetooth: add BluetoothInputClient
[chromium-blink-merge.git] / net / url_request / view_cache_helper.h
blob2723d33244374dd6ac9c59741e8a272fc14bf657
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.
5 #ifndef NET_URL_REQUEST_VIEW_CACHE_HELPER_H_
6 #define NET_URL_REQUEST_VIEW_CACHE_HELPER_H_
7 #pragma once
9 #include <string>
11 #include "base/memory/weak_ptr.h"
12 #include "net/base/completion_callback.h"
13 #include "net/base/io_buffer.h"
14 #include "net/base/net_export.h"
16 namespace disk_cache {
17 class Backend;
18 class Entry;
19 } // namespace disk_cache
21 namespace net {
23 class URLRequestContext;
25 class NET_EXPORT ViewCacheHelper {
26 public:
27 ViewCacheHelper();
28 ~ViewCacheHelper();
30 // Formats the cache information for |key| as HTML. Returns a net error code.
31 // If this method returns ERR_IO_PENDING, |callback| will be notified when the
32 // operation completes. |out| must remain valid until this operation completes
33 // or the object is destroyed.
34 int GetEntryInfoHTML(const std::string& key,
35 const URLRequestContext* context,
36 std::string* out,
37 const CompletionCallback& callback);
39 // Formats the cache contents as HTML. Returns a net error code.
40 // If this method returns ERR_IO_PENDING, |callback| will be notified when the
41 // operation completes. |out| must remain valid until this operation completes
42 // or the object is destroyed. |url_prefix| will be prepended to each entry
43 // key as a link to the entry.
44 int GetContentsHTML(const URLRequestContext* context,
45 const std::string& url_prefix,
46 std::string* out,
47 const CompletionCallback& callback);
49 // Lower-level helper to produce a textual representation of binary data.
50 // The results are appended to |result| and can be used in HTML pages
51 // provided the dump is contained within <pre></pre> tags.
52 static void HexDump(const char *buf, size_t buf_len, std::string* result);
54 private:
55 enum State {
56 STATE_NONE,
57 STATE_GET_BACKEND,
58 STATE_GET_BACKEND_COMPLETE,
59 STATE_OPEN_NEXT_ENTRY,
60 STATE_OPEN_NEXT_ENTRY_COMPLETE,
61 STATE_OPEN_ENTRY,
62 STATE_OPEN_ENTRY_COMPLETE,
63 STATE_READ_RESPONSE,
64 STATE_READ_RESPONSE_COMPLETE,
65 STATE_READ_DATA,
66 STATE_READ_DATA_COMPLETE
69 // Implements GetEntryInfoHTML and GetContentsHTML.
70 int GetInfoHTML(const std::string& key,
71 const URLRequestContext* context,
72 const std::string& url_prefix,
73 std::string* out,
74 const CompletionCallback& callback);
76 // This is a helper function used to trigger a completion callback. It may
77 // only be called if callback_ is non-null.
78 void DoCallback(int rv);
80 // This will trigger the completion callback if appropriate.
81 void HandleResult(int rv);
83 // Runs the state transition loop.
84 int DoLoop(int result);
86 // Each of these methods corresponds to a State value. If there is an
87 // argument, the value corresponds to the return of the previous state or
88 // corresponding callback.
89 int DoGetBackend();
90 int DoGetBackendComplete(int result);
91 int DoOpenNextEntry();
92 int DoOpenNextEntryComplete(int result);
93 int DoOpenEntry();
94 int DoOpenEntryComplete(int result);
95 int DoReadResponse();
96 int DoReadResponseComplete(int result);
97 int DoReadData();
98 int DoReadDataComplete(int result);
100 // Called to signal completion of asynchronous IO.
101 void OnIOComplete(int result);
103 scoped_refptr<const URLRequestContext> context_;
104 disk_cache::Backend* disk_cache_;
105 disk_cache::Entry* entry_;
106 void* iter_;
107 scoped_refptr<IOBuffer> buf_;
108 int buf_len_;
109 int index_;
111 std::string key_;
112 std::string url_prefix_;
113 std::string* data_;
114 CompletionCallback callback_;
116 State next_state_;
118 base::WeakPtrFactory<ViewCacheHelper> weak_factory_;
120 DISALLOW_COPY_AND_ASSIGN(ViewCacheHelper);
123 } // namespace net.
125 #endif // NET_URL_REQUEST_VIEW_CACHE_HELPER_H_