OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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 CONTENT_RENDERER_MANIFEST_MANIFEST_MANAGER_H_ |
| 6 #define CONTENT_RENDERER_MANIFEST_MANIFEST_MANAGER_H_ |
| 7 |
| 8 #include <list> |
| 9 |
| 10 #include "base/callback_forward.h" |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "content/public/common/manifest.h" |
| 13 #include "content/public/renderer/render_frame_observer.h" |
| 14 |
| 15 namespace blink { |
| 16 class WebURLResponse; |
| 17 } |
| 18 |
| 19 namespace content { |
| 20 |
| 21 class ManifestFetcher; |
| 22 |
| 23 // The ManifestManager is a helper class that takes care of fetching and parsing |
| 24 // the Manifest of the associated RenderFrame. It uses the ManifestFetcher and |
| 25 // the ManifestParser in order to do so. |
| 26 // There are two expected consumers of this helper: ManifestManagerHost, via IPC |
| 27 // messages and callers inside the renderer process. The latter should use |
| 28 // GetManifest(). |
| 29 class ManifestManager : public RenderFrameObserver { |
| 30 public: |
| 31 typedef base::Callback<void(const Manifest&)> GetManifestCallback; |
| 32 |
| 33 explicit ManifestManager(RenderFrame* render_frame); |
| 34 virtual ~ManifestManager(); |
| 35 |
| 36 // Will call the given |callback| with the Manifest associated with the |
| 37 // RenderFrame if any. Will pass an empty Manifest in case of error. |
| 38 void GetManifest(const GetManifestCallback& callback); |
| 39 |
| 40 // RenderFrameObserver implementation. |
| 41 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 42 |
| 43 protected: |
| 44 friend RenderFrameImpl; |
| 45 |
| 46 // Called by the RenderFrameImpl when it receives signal from Blink that the |
| 47 // page's manifest might have changed. |
| 48 void ManifestChanged(); |
| 49 |
| 50 private: |
| 51 enum ResolveState { |
| 52 ResolveStateSuccess, |
| 53 ResolveStateFailure |
| 54 }; |
| 55 |
| 56 // Called when receiving a ManifestManagerMsg_RequestManifest from the browser |
| 57 // process. |
| 58 void OnRequestManifest(int request_id); |
| 59 void OnRequestManifestComplete(const Manifest&); |
| 60 |
| 61 void DownloadManifest(); |
| 62 void OnManifestFetchComplete(const blink::WebURLResponse& response, |
| 63 const std::string& data); |
| 64 void ResolveCallbacks(ResolveState state); |
| 65 |
| 66 scoped_ptr<ManifestFetcher> fetcher_; |
| 67 |
| 68 // Whether the RenderFrame may have an associated Manifest. If true, the frame |
| 69 // may have a manifest, if false, it can't have one. |
| 70 bool may_have_manifest_; |
| 71 |
| 72 // Whether the current Manifest is dirty. |
| 73 bool manifest_dirty_; |
| 74 |
| 75 // Current Manifest. Might be outdated if manifest_dirty_ is true. |
| 76 Manifest manifest_; |
| 77 |
| 78 // FIFO list of request_id's received from the browser process. |
| 79 std::list<int> request_ids_; |
| 80 |
| 81 std::list<GetManifestCallback> pending_callbacks_; |
| 82 |
| 83 DISALLOW_COPY_AND_ASSIGN(ManifestManager); |
| 84 }; |
| 85 |
| 86 } // namespace content |
| 87 |
| 88 #endif // CONTENT_RENDERER_MANIFEST_MANIFEST_MANAGER_H_ |
OLD | NEW |