file_growth.cc revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file. 45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ppapi/shared_impl/file_growth.h" 65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/logging.h" 85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace ppapi { 105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)FileGrowth::FileGrowth() 125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) : max_written_offset(0), 135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) append_mode_write_amount(0) { 145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)FileGrowth::FileGrowth(int64_t max_written_offset, 175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int64_t append_mode_write_amount) 185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) : max_written_offset(max_written_offset), 195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) append_mode_write_amount(append_mode_write_amount) { 205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DCHECK_LE(0, max_written_offset); 215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DCHECK_LE(0, append_mode_write_amount); 225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)FileGrowthMap FileSizeMapToFileGrowthMapForTesting( 255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const FileSizeMap& file_sizes) { 265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) FileGrowthMap file_growths; 275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) for (FileSizeMap::const_iterator it = file_sizes.begin(); 285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) it != file_sizes.end(); ++it) 295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) file_growths[it->first] = FileGrowth(it->second, 0); 305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return file_growths; 315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)FileSizeMap FileGrowthMapToFileSizeMapForTesting( 345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const FileGrowthMap& file_growths) { 355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) FileSizeMap file_sizes; 365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) for (FileGrowthMap::const_iterator it = file_growths.begin(); 375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) it != file_growths.end(); ++it) 385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) file_sizes[it->first] = it->second.max_written_offset; 395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return file_sizes; 405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} // namespace ppapi 43