OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "content/common/service_worker/service_worker_traits.h" |
| 6 |
| 7 #include "base/strings/stringprintf.h" |
| 8 #include "content/common/service_worker/service_worker_client_info.h" |
| 9 #include "content/public/common/common_param_traits.h" |
| 10 |
| 11 using content::ServiceWorkerClientInfo; |
| 12 |
| 13 namespace IPC { |
| 14 |
| 15 void ParamTraits<ServiceWorkerClientInfo>::Write( |
| 16 Message* m, const ServiceWorkerClientInfo& p) { |
| 17 m->WriteBool(p.IsEmpty()); |
| 18 if (p.IsEmpty()) |
| 19 return; |
| 20 m->WriteInt(p.client_id()); |
| 21 m->WriteInt(static_cast<int>(p.page_visibility_state())); |
| 22 m->WriteBool(p.is_focused()); |
| 23 ParamTraits<GURL>::Write(m, p.url()); |
| 24 m->WriteInt(static_cast<int>(p.frame_type())); |
| 25 } |
| 26 |
| 27 bool ParamTraits<ServiceWorkerClientInfo>::Read(const Message* m, |
| 28 PickleIterator* iter, |
| 29 ServiceWorkerClientInfo* r) { |
| 30 bool is_empty; |
| 31 if (!iter->ReadBool(&is_empty)) |
| 32 return false; |
| 33 if (is_empty) { |
| 34 *r = ServiceWorkerClientInfo(); |
| 35 return true; |
| 36 } |
| 37 |
| 38 GURL url; |
| 39 bool is_focused; |
| 40 int client_id, page_visibility_state, frame_type; |
| 41 |
| 42 if (!iter->ReadInt(&client_id) || |
| 43 !iter->ReadInt(&page_visibility_state) || |
| 44 !iter->ReadBool(&is_focused) || |
| 45 !ParamTraits<GURL>::Read(m, iter, &url) || |
| 46 !iter->ReadInt(&frame_type)) |
| 47 return false; |
| 48 |
| 49 ServiceWorkerClientInfo client_info( |
| 50 static_cast<blink::WebPageVisibilityState>(page_visibility_state), |
| 51 is_focused, |
| 52 url, |
| 53 static_cast<content::RequestContextFrameType>(frame_type)); |
| 54 client_info.SetClientID(client_id); |
| 55 *r = client_info; |
| 56 return true; |
| 57 } |
| 58 |
| 59 void ParamTraits<ServiceWorkerClientInfo>::Log(const ServiceWorkerClientInfo& p, |
| 60 std::string* l) { |
| 61 l->append(base::StringPrintf("<ServiceWorkerClientInfo>")); |
| 62 } |
| 63 |
| 64 } |
OLD | NEW |