common_param_traits.cc revision ddb351dbec246cf1fab5ec20d2d5520909041de1
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. 4 5#include "chrome/common/common_param_traits.h" 6 7#include "ipc/ipc_message.h" 8#include "ipc/ipc_message_utils.h" 9 10namespace IPC { 11 12void ParamTraits<ContentSetting>::Write(Message* m, const param_type& p) { 13 m->WriteInt(static_cast<int>(p)); 14} 15 16bool ParamTraits<ContentSetting>::Read(const Message* m, void** iter, 17 param_type* p) { 18 int type; 19 if (!m->ReadInt(iter, &type)) 20 return false; 21 *p = static_cast<param_type>(type); 22 return true; 23} 24 25void ParamTraits<ContentSetting>::Log(const param_type& p, std::string* l) { 26 std::string content_setting; 27 switch (p) { 28 case CONTENT_SETTING_DEFAULT: 29 content_setting = "CONTENT_SETTING_DEFAULT"; 30 break; 31 case CONTENT_SETTING_ALLOW: 32 content_setting = "CONTENT_SETTING_ALLOW"; 33 break; 34 case CONTENT_SETTING_BLOCK: 35 content_setting = "CONTENT_SETTING_BLOCK"; 36 break; 37 case CONTENT_SETTING_ASK: 38 content_setting = "CONTENT_SETTING_ASK"; 39 break; 40 case CONTENT_SETTING_SESSION_ONLY: 41 content_setting = "CONTENT_SETTING_SESSION_ONLY"; 42 break; 43 default: 44 content_setting = "UNKNOWN"; 45 break; 46 } 47 LogParam(content_setting, l); 48} 49 50void ParamTraits<ContentSettingsType>::Write(Message* m, const param_type& p) { 51 m->WriteInt(static_cast<int>(p)); 52} 53 54bool ParamTraits<ContentSettingsType>::Read(const Message* m, void** iter, 55 param_type* p) { 56 int type; 57 if (!m->ReadInt(iter, &type)) 58 return false; 59 *p = static_cast<param_type>(type); 60 return true; 61} 62 63void ParamTraits<ContentSettingsType>::Log(const param_type& p, 64 std::string* l) { 65 std::string setting_type; 66 switch (p) { 67 case CONTENT_SETTINGS_TYPE_DEFAULT: 68 setting_type = "CONTENT_SETTINGS_TYPE_DEFAULT"; 69 break; 70 case CONTENT_SETTINGS_TYPE_COOKIES: 71 setting_type = "CONTENT_SETTINGS_TYPE_COOKIES"; 72 break; 73 case CONTENT_SETTINGS_TYPE_IMAGES: 74 setting_type = "CONTENT_SETTINGS_TYPE_IMAGES"; 75 break; 76 case CONTENT_SETTINGS_TYPE_JAVASCRIPT: 77 setting_type = "CONTENT_SETTINGS_TYPE_JAVASCRIPT"; 78 break; 79 case CONTENT_SETTINGS_TYPE_PLUGINS: 80 setting_type = "CONTENT_SETTINGS_TYPE_PLUGINS"; 81 break; 82 case CONTENT_SETTINGS_TYPE_POPUPS: 83 setting_type = "CONTENT_SETTINGS_TYPE_POPUPS"; 84 break; 85 case CONTENT_SETTINGS_TYPE_GEOLOCATION: 86 setting_type = "CONTENT_SETTINGS_TYPE_GEOLOCATION"; 87 break; 88 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: 89 setting_type = "CONTENT_SETTINGS_TYPE_NOTIFICATIONS"; 90 break; 91 case CONTENT_SETTINGS_TYPE_PRERENDER: 92 setting_type = "CONTENT_SETTINGS_TYPE_PRERENDER"; 93 break; 94 default: 95 setting_type = "UNKNOWN"; 96 break; 97 } 98 LogParam(setting_type, l); 99} 100 101} // namespace IPC 102