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)
11a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)FileGrowth::FileGrowth() : max_written_offset(0), append_mode_write_amount(0) {}
125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)FileGrowth::FileGrowth(int64_t max_written_offset,
145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                       int64_t append_mode_write_amount)
155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    : max_written_offset(max_written_offset),
165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      append_mode_write_amount(append_mode_write_amount) {
175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DCHECK_LE(0, max_written_offset);
185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DCHECK_LE(0, append_mode_write_amount);
195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)FileGrowthMap FileSizeMapToFileGrowthMapForTesting(
225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const FileSizeMap& file_sizes) {
235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  FileGrowthMap file_growths;
245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  for (FileSizeMap::const_iterator it = file_sizes.begin();
25a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)       it != file_sizes.end();
26a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)       ++it)
275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    file_growths[it->first] = FileGrowth(it->second, 0);
285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return file_growths;
295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)FileSizeMap FileGrowthMapToFileSizeMapForTesting(
325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const FileGrowthMap& file_growths) {
335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  FileSizeMap file_sizes;
345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  for (FileGrowthMap::const_iterator it = file_growths.begin();
35a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)       it != file_growths.end();
36a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)       ++it)
375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    file_sizes[it->first] = it->second.max_written_offset;
385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return file_sizes;
395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}  // namespace ppapi
42